From: "David A. Black" Date: 2007-10-15T20:07:16+09:00 Subject: Re: Parameter in a block is not local? Hi -- On Mon, 15 Oct 2007, SpringFlowers AutumnMoon wrote: > David A. Black wrote: >> Hi -- >> >> On Mon, 15 Oct 2007, SpringFlowers AutumnMoon wrote: >> >>> >>> foo(i) >>> 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. > > So in a way, think of a code block like a "if" statement? (no new local > scope) I think the best thing is to learn about blocks as blocks, and don't worry too much about how much they are or aren't similar to other things. A block has the variables from the local scope in which it was created, and can also create its own variables, but the ones it creates exist only inside the block. An if statement is truly flat with regard to its local scope. 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!