Project

General

Profile

Feature #14548

Allow some_array&.[1] to be a valid syntax

Added by rosenfeld (Rodrigo Rosenfeld Rosas) over 1 year ago. Updated 25 days ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:85784]

Description

Currently, Ruby allows accessing an array's index while testing whether the array is not nil with this syntax: my_array&.[](1). I've always found this awkward but didn't mind about suggesting anything to improve this.

I was just reading about how JavaScript is probably going to support myArray?.[1] and found that it read good enough for me.

So I'd like to propose about the same syntax, replacing ?. with the Ruby equivalent &. instead. How does that look like to you?

History

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

It was introduced at r52422 once, but removed soon at r52430 by a matz's objection.

#2

Updated by znz (Kazuhiro NISHIYAMA) 11 months ago

  • Description updated (diff)

Updated by matz (Yukihiro Matsumoto) 25 days ago

  • Status changed from Open to Rejected

And it's too confusing. ary&.[] and ary&.[]() for example.

Also available in: Atom PDF