From: Jacob Fugal Date: 2009-03-03T13:46:52+09:00 Subject: [ruby-core:22635] Re: Question: lambda and yield Take the following with a grain of salt; I'm not a core expert, I just play one on TV. ;) If I'm wrong, just let me know. That said, I'm pretty sure that... Try the following code. You'll see that the puts after the yield isn't even evaluated. The return statement within the lambda is "bound" (for lack of a better word) to the method where the lambda was defined, not the lambda itself. The statement is rebound to the Proc object when the lambda is converted to a Proc, but remains bound to the caller when yielded to. Moral of the story: avoid return in lambdas and procs unless you really want to explode a later code reader's brain. :) Jacob Fugal -- def call_block(&l) l.call end def yield_block yield end def lambda_and_call l = lambda { return 1 } x = call_block(&l) + 1 puts "lambda_and_call: #{x}" end def lambda_and_yield l = lambda { return 1 } x = yield_block(&l) + 1 puts "lambda_and_yield: #{x}" end lambda_and_call lambda_and_yield