title: Ruby variable assignment in a conditional "if" modifier
body: <p>I have a question about how the Ruby interpreter assigns variables:</p>
  
  <p>I use this quite often:</p>
  
  <pre><code>return foo if (foo = bar.some_method)
  </code></pre>
  
  <p>where some_method returns an object or nil.</p>
  
  <p>However, when I try this:</p>
  
  <pre><code>return foo if (true &amp;&amp; (foo = bar.some_method))
  </code></pre>
  
  <p>I get: NameError: undefined local variable or method foo for main:Object.</p>
  
  <p>What is the difference in evaluation between the first and second lines that causes the second line to error?</p>