If I do the following with warnings turned on under Ruby 1.9:
$VERBOSE = true
x = 42
5.times{|x| puts x}
I get
warning: shadowing outer local variable - x
Presumably it’s to do with using x as a block parameter as well as a variable outside of the block, but what does “shadowing” mean?
Shadowing is when you have two different local variables with the same name. It is said that the variable defined in the inner scope “shadows” the one in the outer scope (because the outer variable is now no longer accessible as long as the inner variable is in scope, even though it would otherwise be in scope).
So in your case, you can’t access the outer
xvariable in your block, because you have an inner variable with the same name.