title: Why does ruby treat variables differently inside 'def' and 'define_method'?
body: <p>Ruby treats local variables differently inside <code>def</code> and inside <code>define_method</code>:</p>
  
  <pre><code>class MyClass
    y = 2
    def foo
      y ||= 0
      puts y
    end
  
    define_method :bar do
      y ||= 0
      puts y
    end
  end
  
  my_class = MyClass.new
  my_class.foo # =&gt; 0
  my_class.bar # =&gt; 2
  </code></pre>
  
  <p>I am wondering why.</p>