当前位置 : 主页 > 编程语言 > ruby >

在Ruby中,可以显式创建局部变量

来源:互联网 收集:自由互联 发布时间:2021-06-23
例如 x = 123p = Proc.new { x = 'I do not want change the value of the outer x, I want to create a local x'} 在Ruby中是否有与Perl中的“my”关键字相同的东西? 根据 my 的Perl文档,我认为你在Ruby中寻找类似下面
例如

x = 123
p = Proc.new {
  x = 'I do not want change the value of the outer x, I want to create a local x'
}

在Ruby中是否有与Perl中的“my”关键字相同的东西?

根据 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
网友评论