title: I don't understand ruby local scope
body: <p>In this example, </p>
  
  <pre><code>def foo(x)
    if(x &gt; 5)
      bar = 100
    end
    puts bar
  end
  </code></pre>
  
  <p>Then foo(6)    Outputs: 100
  and foo(3) outputs nothing.</p>
  
  <p>However if i changed the definition to</p>
  
  <pre><code>def foo(x)
    if(x &gt; 5)
      bar = 100
    end
    puts bob
  end
  </code></pre>
  
  <p>I get an "undefined local variable or method" error.  </p>
  
  <p>So my question is why I am not getting this error when I call foo(3) and bar is never set?</p>