红宝石。(条件)?return:next。返回错误

sea*_*mus 0 ruby if-statement next

(1<2) ? return : next
Run Code Online (Sandbox Code Playgroud)

dos.rb:dos.rb:74:下一个无效(SyntaxError)

在这种情况下,告诉红宝石“继续”的正确方法是什么。

如果1小于2,则离开函数,否则继续前进

Dar*_*tle 5

您可以说:

return if (1 < 2)
Run Code Online (Sandbox Code Playgroud)

您不必告诉Ruby“继续前进”-如果它不从函数返回,它将执行该操作!