Project

General

Profile

Actions

Feature #12263

closed

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

Added by johnnyshields (Johnny Shields) almost 8 years ago. Updated almost 8 years ago.

Status:
Feedback
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
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0