title: Block binding in Ruby
body: <p>I am confused by the definition of block binding in ruby. Here are two samples:</p>
  
  <pre><code>def redfine_a(&amp;block)
    a = 2
    puts eval("a", block.binding)
    block.call
  end
  a = "hello"
  puts redfine_a {a}
  </code></pre>
  
  <p>This one could run with the expected result, while the second one:</p>
  
  <pre><code>def redefine_a(&amp;block)
    a= 2
    puts eval("a", block.binding)
    block.call
  end
  
  puts redefine_a{a= "hello"}
  </code></pre>
  
  <p>will complain:</p>
  
  <pre><code>undefined local variable or method `a' for main:Object (NameError)
  </code></pre>
  
  <p>After I removed the <code>puts eval("a", block.binding)</code>, my code run:</p>
  
  <pre><code>def redefine_a(&amp;block)
    a= 2
    block.call
  end
  
  puts redefine_a{a= "hello"}
  </code></pre>
  
  <p>Where am I wrong?</p>