Project

General

Profile

Bug #6203

Updated by nobu (Nobuyoshi Nakada) over 12 years ago

=begin 
 When I use Array#values_at I expect that it would be the same as successive calls to (({Array#[]})). 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})). 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})) Array#values_at be equivalent to successive calls to (({Array#[]})). Array#[]. I have patched (({rb_range_beg_len()})) rb_range_beg_len() to handle the extra case and opened a pull request on github. 
 =end

Back