Issue #6203 has been updated by marcandre (Marc-Andre Lafortune).


Matz, could you please confirm what return value is correct for `[].values_at(1..3)`?

1) It could be []. This would be compatible with Ruby 1.8 & 1.9.
2) It could be [nil, nil, nil]. This is current behavior in trunk after Nobu's commit, but with potential incompatibility.

If 1, trunk must be changed
If 2, NEWS must list incompatibility.

Nobu: in either case, any reason not to commit my patch in [#5]?

Thanks
----------------------------------------
Bug #6203: Array#values_at does not handle ranges with end index past the end of the array
https://bugs.ruby-lang.org/issues/6203#change-33084

Author: ferrous26 (Mark Rada)
Status: Open
Priority: Normal
Assignee: nobu (Nobuyoshi Nakada)
Category: core
Target version: 2.0.0
ruby -v: trunk


=begin
When I use Array#values_at I expect that it would be the same as successive calls to (({Array#[]})).

There is one case where this does not hold:

    a = [0,1,2,3,4,5]
    a[4..6] # => [4, 5]
    a.values_at(4..6) # => [4,5,nil]

I think this is an inconsistency in the design of (({Array#values_at})). We can look at a more extreme case:

    a[4..100] # => [4, 5]
    a.values_at 4..100 # => [4, 5, nil]

And now it doesn't make any sense.

I think the best solution would be to make (({Array#values_at})) be equivalent to successive calls to (({Array#[]})). I have patched (({rb_range_beg_len()})) to handle the extra case and opened a pull request on github.
=end


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