title: What happens during `begin; return; ensure`?
body: <p>I was looking into the internals of a gem, and ran into the following pattern:</p>
  
  <pre><code>def foo
    begin
      return 'foo'
    ensure
      puts 'bar'
    end
  end
  foo
  </code></pre>
  
  <p>This will print the strings <code>'foo'</code> and <code>'bar'</code> to <code>STDOUT</code>. How does this happen? My naive understanding would be that when you encounter a <code>return</code> statement, then you pop the call off the stack and return the value specified by return. I would imagine that if this were the case, then you would not then be able to execute the <code>ensure</code> block. Obviously the <code>ensure</code> block is executed. I'm curious as to how this is happening.  How is this behavior implemented?</p>