Note that there are some explanatory texts on larger screens.

plurals
  1. POCommon Ruby Idioms
    primarykey
    data
    text
    <p>One thing I love about ruby is that mostly it is a very readable language (which is great for self-documenting code)</p> <p>However, inspired by this question: <a href="https://stackoverflow.com/questions/609612/ruby-code-explained">Ruby Code explained</a> and the description of how <code>||=</code> works in ruby, I was thinking about the ruby idioms I don't use, as frankly, I don't fully grok them.</p> <p>So my question is, similar to the example from the referenced question, what common, but not obvious, ruby idioms do I need to be aware of to be a truly proficient ruby programmer?</p> <p>By the way, from the referenced question</p> <pre><code>a ||= b </code></pre> <p>is equivalent to</p> <pre><code>if a == nil || a == false a = b end </code></pre> <p>(Thanks to Ian Terrell for the correction)</p> <p><strong>Edit:</strong> It turns out this point is not totally uncontroversial. The correct expansion is in fact</p> <pre><code>(a || (a = (b))) </code></pre> <p>See these links for why:</p> <ul> <li><a href="http://DABlog.RubyPAL.Com/2008/3/25/a-short-circuit-edge-case/" rel="nofollow noreferrer">http://DABlog.RubyPAL.Com/2008/3/25/a-short-circuit-edge-case/</a></li> <li><a href="http://DABlog.RubyPAL.Com/2008/3/26/short-circuit-post-correction/" rel="nofollow noreferrer">http://DABlog.RubyPAL.Com/2008/3/26/short-circuit-post-correction/</a></li> <li><a href="http://ProcNew.Com/ruby-short-circuit-edge-case-response.html" rel="nofollow noreferrer">http://ProcNew.Com/ruby-short-circuit-edge-case-response.html</a> </li> </ul> <p>Thanks to Jörg W Mittag for pointing this out.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    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