title: Ruby: Variables defined in If/else statement are accessible outside of if/else?
body: <pre><code>def foo
    #bar = nil
    if true
      bar = 1
    else
      bar = 2
    end
    bar #&lt;-- shouldn't this refer to nil since the bar from the if statement is removed from the stack?
  end
  
  puts foo # prints "1"
  </code></pre>
  
  <p>I always thought you had to make a temporary variable and define it as nil or an initial value so that variables defined inside an if/else statement would persist outside the scope of the if/else statement and not disappear off the stack?? Why does it print 1 and not nil?</p>