def foo
f = Proc.new { return "return from foo from inside proc" }
f.call # control leaves foo here
return "return from foo"
end
def bar
f = lambda { return "return from lambda" }
f.call # control does not leave bar here
return "return from bar"
end
puts foo # prints "return from foo from inside proc"
puts bar # prints "return from bar"
从中可以看出 Proc.new 中的block 执行的时候当作方法内的一个片段代码去执行, 而lambda则是在block已经执行完成了.
通俗的说就是 Proc返回的是block内还未执行的代码, 而lambda返回的则是block已经执行完成的结果.