Project

General

Profile

Actions

Feature #16451

open

Special ternary operator for methods ending in `?`

Added by myxoh (Nicolas Klein) over 4 years ago. Updated over 4 years ago.

Status:
Open
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'
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0