From: "rits (First Last)" Date: 2013-08-02T03:58:48+09:00 Subject: [ruby-core:56308] [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). nobu (Nobuyoshi Nakada) wrote: > `return' always returns from the enclosing method. That is not true, and so by design, from "The ruby programming language": As we said earlier, lambdas work more like methods than blocks. A return statement in a lambda, therefore, returns from the lambda itself, not from the method that surrounds the creation site of the lambda. ___________ This bug is an exception to this rule, one that does not make sense. If there is a good reason for it, you have not given it. If this behavior is not a bug (i.e. by design) then please answer: what is the reason for this exception to the general lambda rule? why should yield and block.call behave differently? why should lambdas sometimes not have lambda semantics? When the code is written it has to assume lambda or proc semantics, it can't handle both, so why should the semantics vary? __________________________________________ Can anything be done about broken email alerts on bugs.ruby-lang.org? ---------------------------------------- Bug #8693: lambda invoked by yield acts as a proc with respect to return https://bugs.ruby-lang.org/issues/8693#change-40802 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/