Issue #16141 has been updated by sawa (Tsuyoshi Sawada).


This is exactly what I have proposed in #15950. I believe this feature shou=
ld gain more popularity.


----------------------------------------
Feature #16141: Change in the array[x,y] notation.
https://bugs.ruby-lang.org/issues/16141#change-81386

* Author: professeurx (Fran=E7oys Proulx)
* Status: Closed
* Priority: Normal
* Assignee: =

* Target version: =

----------------------------------------

It not a bug, but it's an oddity of the language.

``` ruby
array_four  =3D %w[a b c d e f g] =


p array_four[1,3]  =

p array_four[-1,3]  =

p array_four[3,3] =

p array_four[-3,2] =

p array_four[-3, -2] =


["b", "c", "d"]
["g"]
["d", "e", "f"]
["e", "f"]
nil

```
p array_four[-3, -2]  do not follow the principal of the least surprise!
the logical output would be ["d", "e"]

The way i see this
p array_four[-3,2] # take 3 step from the end and take 2 elements increment=
ally =


and
p array_four[-3,-2] # take 3 step from the end and take 2 elements decremen=
tally

The change wouldn't affect the retro-compatibility of the language.





-- =

https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=3Dunsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>