From: mortee Date: 2007-10-15T09:54:32+09:00 Subject: Re: Parameter in a block is not local? SpringFlowers AutumnMoon wrote: > Pat Maddox wrote: >> 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. > > when compared to the following it is surprising: > > a = 1 > p a > > def foo(a) > p a > end > > for i in 1..10 > foo(i) > end > > p a > > ------------------ > > E:\>ruby test_iterator2.rb > 1 > 1 > 2 > 3 > 4 > 5 > 6 > 7 > 8 > 9 > 10 > 1 > Yes, the def syntax specifically doesn't take the caller binding, AFAIK. If you intend having methods access variables local to where they are defined, just use define_method, which takes a block, with all of its peculiarities, like taking the caller binding along with its local variables. mortee