From: dblack@... Date: 2006-02-28T23:14:26+09:00 Subject: Re: Same variable name used in block and local question Hi -- On Tue, 28 Feb 2006, Robert Klemme wrote: > rubyrus wrote: >> Can anybody help me here, TIA!! >> >> This is the code. I expect to see the string "Afterward:turkey", but >> why am I getting "Afterward:camel"? |animal| parameter in a block >> should be temporary inside the block, right?? > > No, it isn't because it was defined outside the block. It's used in cases > like > > count = 0 > arr.each { count += 1 } > puts "count=#{count}" > > If you want to keep it local you must not define it in the surrounding > scope. I think that's a different thing, though, from the parameter semantics. As I understand it, in 2.0 things would work like this: count = 0 other = "zero" [1,2,3].each {|other| count += 1 } # count is now 3 # other is still "zero" I may be getting it wrong... but I think the scoping of parameter variables and other block variables is going to diverge. David -- David A. Black (dblack@wobblini.net) Ruby Power and Light (http://www.rubypowerandlight.com) "Ruby for Rails" chapters now available from Manning Early Access Program! http://www.manning.com/books/black