Quantcast
Channel: Ruby Issue Tracking System: shevegen (Robert A. Heiler)
Viewing all articles
Browse latest Browse all 100

Ruby master - Misc #16678: Array#values_at has unintuitive behavior when supplied a range startin...

$
0
0

Actually .values_at() confused me when I tried to use my go-to method for
obtaining a slice from an Array:

a[3..5] # => [4, 5]

There I wondered why it did not return the same. :-)

But anyway; I believe the question is what -1 refers to. It should be the
last entry, right? Ok, so what should the 3 indicate? I think you reason
that it should refer to the fourth entry (I think ... if an Array count
begins at 0, then 3 would refer to the fourth entry). So from that point
of view I actually do not even disagree with you; perhaps I may have
missed some other explanation. (There is probably another explanation;
I think this has come up in the past too. I forgot the explanation,
though, if there was one.)

Personally I will stick with [] an leave .values_at() to others. I am
just so used to [] there. ;-)


Viewing all articles
Browse latest Browse all 100

Trending Articles