On Fri, Jul 10, 2009 at 3:02 PM, Laurent Sansonetti<lsansonetti@apple.com> wrote:
Now, consider:
def foo begin yield ensure p :ok end end def bar foo { return 42 } end p bar
Here you don't have a choice, since you need to honor the ensure block.
In Ruby, return is semantically similar to an exception in some cases. This is unfortunate :-)
Return isn't really an exception, since you can't catch/rescue it. The issue here is that ensure blocks are a hard requirement, and they must fire even if a non-local return unrolls through them. The return here doesn't necessarily need to be implemented as an exception, but it does need to fire ensure blocks. In JRuby, we do use an exception, but we don't have any other way of unrolling the stack. - Charlie