Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think the key to understand that code (I haven't read the book) is that <code>@hide_edit_links</code> is not a boolean, it's just some kind of tag. If <code>@hide_edit_links</code> is not <code>nil</code> ( it doesn't matter which object type it's) then hide_edit_links?` will return true.</p> <p>I have to say that the code <strong>is not at all</strong> straight forward, it's definitely convoluted and complicated (probably without any reason)</p> <p>Example 1 (New instance, without <code>@hide_edit_links</code> set, so it shows link). </p> <ul> <li>The class is instantiated (this code is not in the original question, but I assume it's there), and since there's not reference to <code>@hide_edit_links</code>, the value of the instace variable is <code>nil</code></li> <li>When <code>hide_edit_links?</code> is invoked from the page, <code>@hide_edit_links</code> is nil, so <code>@hide_edit_links.nil?</code> returns true, and thus <code>not @hide_edit_links.nil?</code> is false. </li> <li>Since the page uses <code>unless hide_edit_links?</code>, it shows the link.</li> </ul> <p>Example 2 (New instance, with <code>@hide_edit_links</code> set with an object, so it doesn't show the link). </p> <ul> <li>The class is instantiated and <code>@hide_edit_links</code> is set to a value which is not <code>nil</code>.</li> <li>When <code>hide_edit_links?</code> is invoked from the page, <code>@hide_edit_links</code> is <strong>not</strong> nil, so <code>@hide_edit_links.nil?</code> returns false, and thus <code>not @hide_edit_links.nil?</code> is true. </li> <li>Since the page uses <code>unless hide_edit_links?</code>, it doesn't show the link.</li> </ul> <p>Sorry about the trivial examples... the 'feature' is not complicated, but the solution used by the author looks terribly complicated to my dumb brain.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload