From: David Alan Black Date: 2004-04-18T03:09:09+09:00 Subject: Re: New Local Variable Scope rule Hi -- ts writes: > >>>>> "D" == David Alan Black writes: > > D> Going back to the original point (more or less): I'm just a little > D> perplexed by the whole idea of closures (blocks, Procs, lambdas) > D> having this compile-time effect on local variables in their context of > D> creation. > > Well, actually this is at compile time that ruby make the difference > between local, block-local variable and method call. > > If I've well understood, in 2.0 this is not changed : the only difference > is how ruby make the difference between local and block-local variable. That's my understanding too (see above). I'm just not entirely comfortable with it. > Now the worst case is perhaps this > > svg% cat b.rb > #!/usr/bin/ruby > thr = [] > 5.times do |i| > thr << Thread.new do > a = i > Thread.stop > puts a > end > end > > thr.each {|t| t.run } > svg% > > svg% b.rb > 0 > 1 > 2 > 3 > 4 > svg% > > I'm not sure but I think that for 2.0 all threads will give the same > result. I assume so; it's like your other example, where 2.0 behaves the way pre-2.0 does with "a = nil" before the block. To avoid it I guess you'd have to do: ... Thread.new do |a| # etc. to create a new 'a' each time. David -- David A. Black dblack@wobblini.net