是否可以在外循环的方法中调用next:
bot.rb
while Option.daemon_active?(daemon: "bot")
.....
Trade.market_order
....
end
trade.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
答案 0 :(得分:3)
是。您应该使用throw
和catch
。
bot.rb
while Option.daemon_active?(daemon: "bot")
catch(:foo) do
...
Trade.market_order
...
end
end
trade.rb
class Trade
def self.market_order
...
response = exchange.market_sell
throw :foo if response["state"] == false
end
end