begin
#some routine
rescue
retry
#on third retry, output "no dice!"
end
我想让它在“第三次”重试时打印一条消息。
可能不是最好的解决方案,但一个简单的方法就是制作一个tries
多变的。
tries = 0
begin
# some routine
rescue
tries += 1
retry if tries <= 3
puts "no dice!"
end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)