Project

General

Profile

Actions

Feature #11813

closed

Extend safe navigation operator for [] and []= with syntax sugar

Added by sawa (Tsuyoshi Sawada) almost 9 years ago. Updated over 8 years ago.

Status:
Rejected
Target version:
-
[ruby-core:72093]

Description

Now we have the safe navigation operator &.. But this cannot be used with syntax sugar form of the methods [] and []=, which are more frequent than their ordinary forms of method call. For example, when a can be either an array or nil, we can do:

a &.[](3)
a &.[]= 2, :foo

but we cannot do:

a &.[3]
a &.[2] = :foo

It would be nice if we can extend the use of &. to cover syntactic sugar as above.


Related issues 2 (1 open1 closed)

Related to Ruby master - Bug #11618: Safe call syntax with aref or aset is RejectedActions
Has duplicate Ruby master - Feature #13645: Syntactic sugar for indexing when using the safe navigation operatorOpenActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0