From: Brian Candler Date: 2003-02-13T08:50:04+09:00 Subject: Re: Lexical scope and closures On Thu, Feb 13, 2003 at 08:27:51AM +0900, Hal E. Fulton wrote: > > Matz is thinking of changing the behaviour for a future version of Ruby as > > follows: > > > > (1) block parameters are always locally scoped (so '|x|' in that example > > will behave as if the outside 'x' did not exist, although a warning will > be > > printed because of the re-use of the name; but x will still be 0 after the > > iterator has finished) > > I didn't realize that. So we ARE breaking > old code, eh? Yes. That's one reason for the warning; the other reason is because Matz finds the practice of 'shadowing' distasteful :-) It will also break old code where it depends on a variable introduced in a block being local, e.g. Thread.new { i = 0 ... use i locally } I don't remember seeing a warning for this situation being discussed, but it would seem logical to do so. What you gain: probably less surprising behaviour. "a = 0" always binds to the method scope (whether or not it is inside a block), and "|a|" is always block-local (whether or not 'a' has been used before). Regards, Brian.