bdi*_*ych 3 ruby variables block local proc
例如
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"关键字相同的东西?
根据我的Perl文档,我认为你在Ruby中寻找类似下面的内容: -
x = 123
p = Proc.new {|;x|
x = 'I do not want change the value of the outer x, I want to create a local x'
}
p.call
# => "I do not want change the value of the outer x, I want to create a local x"
x # => 123
Run Code Online (Sandbox Code Playgroud)