gpt4 book ai didi

ruby - 从方法内调用 next 进行外循环

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

是否可以在外循环的方法中调用 next:

bot.rb

while Option.daemon_active?(daemon: "bot")
.....
Trade.market_order
....
end

贸易.rb

class Trade
def self.market_order
... complex code ...
response = exchange.market_sell
next if response["state"] == false # This fails. This should start new iteration of while in bot.rb
end
end

有一个非常相似的问题,但它似乎不适合我:call next on ruby loop from external method

最佳答案

是的。您应该使用 throwcatch

机器人.rb

while Option.daemon_active?(daemon: "bot")
catch(:foo) do
...
Trade.market_order
...
end
end

贸易.rb

class Trade
def self.market_order
...
response = exchange.market_sell
throw :foo if response["state"] == false
end
end

关于ruby - 从方法内调用 next 进行外循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29768878/

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