by wolfish on 4/16/09, 5:59 PM with 15 comments
by tptacek on 4/16/09, 7:46 PM
by mattmcknight on 4/16/09, 7:13 PM
a = 1
for a in 1..2
b = a
end
p a
>> 2
It seems natural that that would change the value of "a", I wouldn't expect a for loop to create a new scoping context. The example with putting a closure into the array is also what I would expect.I am not sure what programming language has the scoping rules he expects, but for me there's nothing to see here, moving along...
by lysium on 4/17/09, 7:58 AM
Edit: I mean in
each { |i| p i }
the |i| stands for a shorthand lambda, that binds an i.And in
for i in 1..3
p i
end
there is no such binding. So where's the problem? That 'for' should use a lambda?by pkulak on 4/17/09, 5:48 PM
by omouse on 4/16/09, 8:27 PM