Think of it this way: Proc.new just create a block of code that is part of the calling function. proc / lambda creates an anonymous function with special bindings. A few code examples will help:
def foo f = Proc.new { return "return from foo from inside Proc.new" } f.call # control leaves foo here return "return from foo" end
equivalently
def foo begin return "return from foo from inside begin/end" } end return "return from foo" end
therefore, it is clear that the return will simply return from the function 'foo'
in contrast:
def foo f = proc { return "return from foo from inside proc" } f.call # control stasy in foo here return "return from foo" end
equivalently (ignoring bindings, as it is not used in this example):
def unonymous_proc return "return from foo from inside proc" end def foo unonymous_proc() return "return from foo" end
It also obviously will not return from foo and will not proceed to the next statement.
Vitaly Kushner Sep 17 '09 at 18:29 2009-09-17 18:29
source share