Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>#tap</code> is a method that basically "passes along" the block to the next. It isn't supposed to "change" the flow of the method. For example</p> <p><a href="http://ruby-doc.org/core-2.0/Object.html#method-i-tap" rel="nofollow">http://ruby-doc.org/core-2.0/Object.html#method-i-tap</a></p> <pre><code>(1..10) .tap {|x| puts "original: #{x.inspect}"} .to_a .tap {|x| puts "array: #{x.inspect}"} .select {|x| x%2==0} .tap {|x| puts "evens: #{x.inspect}"} .map { |x| x*x } .tap {|x| puts "squares: #{x.inspect}"} </code></pre> <p>It's sort of like a unix pipe, but has a chance to access the data as it goes along. like a tap.</p> <p>It is supposed to take something and return the same thing to the next part of the pipe.</p> <p>However, using <code>break a</code> will <strong>break out</strong> of the tap, and <strong>return a</strong>. That is, instead of returning what <code>#tap</code> would normally return (the same thing that it got), it would return <code>a</code> instead.</p> <p>The use of <code>#tap</code> in this case is to pass values down the pipe "as normal", <strong>except</strong> when <code>version</code> is true; in that case it will send along <code>o.send(version)</code> instead.</p> <p>Basically, the normal flow is</p> <pre><code>object.send(attribute_name).send('url') </code></pre> <p>and with <code>tap</code>, it's normally "unchanged". However, using <code>break o.send(version)</code>, the flow is then instead</p> <pre><code>intermediate = object.send(attribute_name); if version return intermediate.send(version).send('url'); # ignore the result of intermediate # and replace it with o.send(version) else return intermediate.send('url'); # maintain normal flow...it's like nothing # was ever tapped end </code></pre>
    singulars
    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. 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