From: Harry Ohlsen Date: 2003-11-17T07:21:15+09:00 Subject: Re: Local Variable Scope in Ruby2 Michael Neumann wrote: > Simple rule (Ruby 2.0): Block parameters are local to the block, > everything else is not. > > Consider the following example (Ruby 1.8): > > a = 3 > [1,2].each do |a| > p a > end > p a # => 2 > > This problem is fixed with 2.0 (a => 3). So, with the new semantics, how do we do things like ... a = nil some_collection.each do |x| if some_condition a = ... break end end Obviously, if we want "a" to end up being the same as one of the values in the collection, there's probably some iterator other than "each" that will allow for that. However, if the value we want to give it is more complex (or just plain different from the current value of x), what's the right mechanism? Sorry, I can't think of a concrete example this second, but I can remember doing this kind of thing many times in the past ... mainly because it always failed until I added the "a = nil" line :-). I ask because I might as well start preparing for when the current mechanism stops working, by using the "right" ... or should that be "Rite" :-) ... code now.