From: "rits (First Last)" Date: 2013-08-04T02:49:00+09:00 Subject: [ruby-core:56358] [ruby-trunk - Bug #8693] lambda invoked by yield acts as a proc with respect to return Issue #8693 has been updated by rits (First Last). =begin boris_stitnicky (Boris Stitnicky) wrote: > @Alexey: It's spec. As soon as you unpack the block with the pretzel, it forgets about its lambda-ness. If you wish to pass lambdas inside the method, you have to do it through the argument list: This notion that & somehow extracts the block from the lambda "shell", throwing the lambda shell away is incorrect. & associates the passed proc/lambda with the block slot of the method, the proc/lambda never goes away, and yield does not invoke a naked block extracted and separated from the lambda but the lambda in the block slot. In the following example you can see that the original lambda is very much alive and when this lambda is invoked with yield it properly complains about argument count. irb(main):006:0> def m1; p Proc.new; yield end; def m2; p l = ->_{return 0}; m1 &l; 1 end; m2 # # ArgumentError: wrong number of arguments (0 for 1) The bottom line is, yield invokes the lambda, and the lambda runs with lambda semantics, with one exception, the return, which must be a bug, ruby is not supposed to have proc/lambda chimeras. ---------------------------------------- Bug #8693: lambda invoked by yield acts as a proc with respect to return https://bugs.ruby-lang.org/issues/8693#change-40863 Author: rits (First Last) Status: Rejected Priority: Normal Assignee: Category: Target version: ruby -v: ruby 2.0.0p247 (2013-06-27) [x64-mingw32] Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN irb(main):004:0> def m1; yield end; def m2; m1 &->{return 0}; 1 end; m2 => 0 -- http://bugs.ruby-lang.org/