From: Eric Mahurin Date: 2005-09-29T00:59:01+09:00 Subject: Re: creating independent lambdas in loops --- Eric Mahurin wrote: > I'm talking about specifically block arguments (the only > variables in a block that can be local to the block). Sorry, the above statement is wrong. After doing some irb experiments I was thinking that only block arguments made local variables. My mistake was that I assumed that the code in a for/in statement was just like a block. Even though it uses #each, I guess the block it gives to each is a different beast: [1,2,3,4].each do |x| y = x end p x # undefined local variable or method p y # undefined local variable or method for x in [1,2,3,4]; y = x; end p x # -> 4 p y # -> 4 [1,2,3,4].each do |x| y = x end p x # -> 4 # for loop defined x before this each loop p y # -> 4 # for loop defined y before this each loop It still seems like there should be a way to controll variable locality in blocks better. Making the variable local just based on whether the variable already exists in the outer scope doesn't cut it. __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com