From: "David A. Black" Date: 2007-10-15T09:16:56+09:00 Subject: Re: Parameter in a block is not local? Hi -- On Mon, 15 Oct 2007, 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 There's no relation or connection between the two. The def keyword always starts a new local scope; the if keyword doesn't. There's no reason to expect them to behave the same way as each other, as they serve entirely different purposes. David -- Upcoming training from Ruby Power and Light, LLC: * Intro to Ruby on Rails, Edison, NJ, October 23-26 * Advancing with Rails, Edison, NJ, November 6-9 Both taught by David A. Black. See http://www.rubypal.com for more info!