如果我执行以下操作并在Ruby 1.9下打开警告:
$VERBOSE = true
x = 42
5.times{|x| puts x}
Run Code Online (Sandbox Code Playgroud)
我明白了
warning: shadowing outer local variable - x
Run Code Online (Sandbox Code Playgroud)
据推测,这与使用x作为块参数以及块外的变量有关,但"阴影"是什么意思?
例如
x = 123
p = Proc.new {
x = 'I do not want change the value of the outer x, I want to create a local x'
}
Run Code Online (Sandbox Code Playgroud)
在Ruby中是否有与Perl中的"my"关键字相同的东西?