title: Why does conditional statement and assigning value in ruby fails if the "if" statement is at end of clause?
body: <p>Why does the last statement (with "if (tmp2 = foo)" at the end of the statement) fail?</p>
  
  <pre><code>def foo;5;end
  
  # this one works
  if (tmp = foo)
    puts tmp.to_s
  end
  
  # why this one fails
  puts tmp2.to_s if (tmp2 = foo) #=&gt; undefined local variable or method ‘tmp2’ for main:Object
  </code></pre>