Feature #12929
closedternary should look ahead w/in a block (and not care about newlines)
Description
Files
Updated by duerst (Martin Dürst) almost 10 years ago
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?
Updated by mutantkeyboard (Antonio Nesic) almost 10 years ago
- File Screen Shot 2016-11-14 at 10.24.39.png Screen Shot 2016-11-14 at 10.24.39.png added
- ruby -v set to 2.3.1
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.
Updated by nobu (Nobuyoshi Nakada) almost 10 years ago
- Tracker changed from Bug to Feature
- Description updated (diff)
- Status changed from Open to Assigned
- Assignee set to matz (Yukihiro Matsumoto)
It is not a bug, and easy to extend the parser to allow that syntax, but doesn't look nice to me.
Updated by matz (Yukihiro Matsumoto) over 9 years ago
I don't think it's worth modifying the syntax. If you want to write complex conditional code, use if-statement.
Matz.
Updated by jeremyevans0 (Jeremy Evans) almost 5 years ago
- Status changed from Assigned to Rejected