From: Pat Maddox Date: 2007-10-15T02:00:53+09:00 Subject: Re: Parameter in a block is not local? On 10/14/07, SpringFlowers AutumnMoon wrote: > I thought a iterator with a block is like an nameless function call... > so if it is a function call, the parameter is local. > but for the following, the output is surprising: > > a = 1 > p a > > 1.upto(10) {|a| p a} > > p a > > -------------- > > E:\>ruby test_iterator.rb > 1 > 1 > 2 > 3 > 4 > 5 > 6 > 7 > 8 > 9 > 10 > 10 > > a is changed! > > but is it true that the "a" is not global to begin with.... > but then, isn't the "a" inside the block more local than the "a" > outside? > > like in Pascal, i think there can be nested functions and therefore, > there will be local and then "local that is more local" than the outer > local. > -- > Posted via http://www.ruby-forum.com/. > > This seems to me along the same lines as a = 1 if true a = 10 end p a # => 10 Which certainly is not surprising or unwelcome. Pat