Project

General

Profile

Feature #16451

Special ternary operator for methods ending in `?`

Added by myxoh (Nicolas Klein) 10 months ago. Updated 10 months ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:96470]

Description

When a method ends in ?, we should be able to skip the ? in the ternary operator. For example, we should be able to do:

question_method? true_statement : false_statement

This shouldn't interfere with implementations, as it currently fails to parse. Below are examples:

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'

Also available in: Atom PDF