Actions
Feature #12929
closedternary should look ahead w/in a block (and not care about newlines)
Feature #12929:
ternary should look ahead w/in a block (and not care about newlines)
Description
Files
Actions
Added by ag4ve (shawn wilson) almost 10 years ago. Updated almost 5 years ago.
Description
Files
| Screen Shot 2016-11-14 at 10.24.39.png (207 KB) Screen Shot 2016-11-14 at 10.24.39.png | mutantkeyboard (Antonio Nesic), 11/14/2016 09:25 AM |
In Ruby, all operators have to be written at the end of the line to make it possible to distinguish between complete statements (with a missing semicolon) and continuations.
The only exception is the '.' operator, which is allowed to be on the next line to make method chaining look better, as follows:
What do you think is special about the ternary operator?
Martin Dürst wrote:
In Ruby, all operators have to be written at the end of the line to make it possible to distinguish between complete statements (with a missing semicolon) and continuations.
The only exception is the '.' operator, which is allowed to be on the next line to make method chaining look better, as follows:
What do you think is special about the ternary operator?
I think that this is what he meant. If he uses IRB, then the syntax error comes up like:
SyntaxError: (irb):14: syntax error, unexpected '?', expecting ')'
from /Users/antonionesic/.rvm/rubies/ruby-2.3.1/bin/irb:11:in `<main>'
But I have to agree. This is a SyntaxError, and not a bug.
Ticket should be closed.
It is not a bug, and easy to extend the parser to allow that syntax, but doesn't look nice to me.
I don't think it's worth modifying the syntax. If you want to write complex conditional code, use if-statement.
Matz.