Project

General

Profile

Feature #12263

Feature request: &&. operator (shorthand for foo && foo.method)

Added by johnnyshields (Johnny Shields) about 4 years ago. Updated about 4 years ago.

Status:
Feedback
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:74852]

Description

Ruby 2.3 introduced the &. safe-navigation operator. I'd like to propose a &&. operator which would be shorthand for:

foo && foo.method

Unlike &., this does not continue the chain if the variable evaluates to false. This would give the following result:

false&.class       # => FalseClass
false&&.class      # => false

false&.inexisting  # => raises NoMethodError
false&&.inexisting # => false

Also available in: Atom PDF