gpt4 book ai didi

ruby - 无法执行 Ruby 中的重试

转载 作者:数据小太阳 更新时间:2023-10-29 08:47:41 24 4
gpt4 key购买 nike

for i in 1..5
retry if i > 2
puts "Value of local variable is #{i}"
end

当我运行上面的代码时,我收到一条错误消息,指出无效重试

我使用的 Ruby 版本是 1.9.3。有人知道代码出了什么问题吗?

最佳答案

从 Ruby 1.9 开始,retry 需要在 rescue 子句中,并且只有在 rescue 子句中才会起作用

关于ruby - 无法执行 Ruby 中的重试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22740459/

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