title: Ruby return in yield block called from a method with ensure
body: <pre><code>def foo
    puts "in foo"
    s = yield
    puts "s = #{s}"
    return 2
  ensure
    puts "in ensure"
    return 1
  end
  
  def bar
    foo do
      puts "in bar block"
      return 3
    end
    return 4
  end
  
  
  [36] pry(main)&gt; r = bar
  in foo
  in bar block
  in ensure
  =&gt; 4
  </code></pre>
  
  <p>I'd expect r = 3 but it turns out it is r = 4.  If I remove the ensure code, r = 3 is expected.  Why is it?</p>
  
  <pre><code>def foo
    puts "in foo"
    s = yield
    puts "s = #{s}"
    return 2
  end
  
  r = bar
  in foo
  in bar block
  =&gt; 3
  </code></pre>