From: David Alan Black Date: 2004-04-14T21:34:23+09:00 Subject: Re: New Local Variable Scope rule Hi -- ts writes: > >>>>> "D" == David Alan Black writes: > > D> def call_foo > D> foo(lambda{|b| c=b}) > > D> puts c # does c persist if the lambda was called? > D> end > > What you have written is similar to > > def call_foo > a = lambda {|b| c = b} > foo(a) > puts c > end > > foo(a) don't change anything and if I've well understood : this is at > compile time that ruby will make the decision (local/block-local) OK... but what will the decision be, for 'c'? Why would it be any different here than for: def foo [1].each { c = 0 } puts c end In both cases, an assignment is being made to c, visible at compile time, in a particular scope. So, in your example (and mine), c is created at compile time in the calling scope (call_foo). Then the lambda is called, and c is actually assigned something. Or is there going to be a further distinction between plain lambdas and code blocks passed to iterators? If so, I really think it's time for a Block class. (Matz: you wanted more reasons.... :-) David -- David A. Black dblack@wobblini.net