[ruby-core:115316] [Ruby master Feature#14548] Allow some_array&.[1] to be a valid syntax

Issue #14548 has been updated by knu (Akinori MUSHA). Status changed from Rejected to Open Assignee set to matz (Yukihiro Matsumoto) Can we reconsider this? JavaScript already introduced this syntax a while ago and we are already getting pretty much used to it. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/... ```javascript obj.val?.prop obj.val?.[expr] obj.func?.(args) ``` I know `ary&.[]` is ambiguous, but it's extremely rare to call `[]` with no arguments, so let's just keep the compatibility and allow it to swallow the following arguments if any. ---------------------------------------- Feature #14548: Allow some_array&.[1] to be a valid syntax https://bugs.ruby-lang.org/issues/14548#change-105233 * Author: rosenfeld (Rodrigo Rosenfeld Rosas) * Status: Open * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) ---------------------------------------- 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? -- https://bugs.ruby-lang.org/
participants (1)
-
knu (Akinori MUSHA)