Reputation: 2901
(1<2) ? return : next
dos.rb: dos.rb:74: Invalid next (SyntaxError)
What is the correct way to tell ruby to 'continue' in this context .
if 1 is less than 2, leave the function, else keep going
Upvotes: 0
Views: 268
Reputation: 369428
return
returns from a method or lambda, next
returns from a block. There is neither a method nor a lambda nor a block in your code, therefore neither return
nor next
are valid in your code.
Upvotes: 4
Reputation: 34031
You can just say:
return if (1 < 2)
You don't have to tell Ruby to "keep going" -- that's what it'll do if it doesn't return from the function!
Upvotes: 5
Reputation: 16568
Just use if instead of a ternary, and be sure you are in a context (such as a loop) where next
is valid.
Upvotes: 2