[ruby-core:96501] [Ruby master Feature#16451] Special ternary operator for methods ending in `?`
[email protected] Thu, 26 Dec 2019 21:03:48 +0000 (UTC)
| Newsgroups | gmane.comp.lang.ruby.core |
|---|---|
| Message-ID | <redmine.journal-83433.20191226210348.6e0e104d49a8edc0@ruby-lang.org> |
Issue #16451 has been updated by Dan0042 (Daniel DeLorme). Also against. I agree that the double question mark looks weird in `foo? ? 1 : 2`, but that's just a code formatting issue and doesn't warrant such an exceptional syntax. xBartu's suggestion is good, or you could customize your editor's syntax highlighting to de-emphasize the second question mark. ---------------------------------------- Feature #16451: Special ternary operator for methods ending in `?` https://bugs.ruby-lang.org/issues/16451#change-83433 * Author: myxoh (Nicolas Klein) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- When a method ends in `?`, we should be able to skip the `?` in the ternary operator. For example, we should be able to do: ```ruby question_method? true_statement : false_statement ``` This shouldn't interfere with implementations, as it currently fails to parse. Below are examples: ```ruby def normal_method; true end def question_method?; false end question_method? ? 'was true' : 'was false' # => 'was false' question_method? 'was true' : 'was false' # => 'was false' normal_method ? 'was true' : 'was false' # => 'was true' ``` -- https://bugs.ruby-lang.org/ Unsubscribe: <mailto:[email protected]?subject=unsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>