gpt4 book ai didi

ruby - 在 Ruby 中是否可以显式创建局部变量

转载 作者:数据小太阳 更新时间:2023-10-29 07:48:10 25 4
gpt4 key购买 nike

例如

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”关键字相同的东西?

最佳答案

根据 myPerl 文档,我想你正在寻找类似下面的 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

关于ruby - 在 Ruby 中是否可以显式创建局部变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18599758/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com