From: Gavin Sinclair Date: 2004-05-08T22:24:14+09:00 Subject: Re: How to get the last 5 elements of an array? On Saturday, May 8, 2004, 10:54:02 PM, David wrote: >> Any thoughts before I raise an RCR? > > Yes. I don't think it makes sense for this: > > arr[-5..-1].include?(arr[-3]) > > to be false, since this: > > (-5..-1).include?(-3) > > is true. Your first condition would be justifiably false if arr == [1,2], even if I submitted an RCR and it were accepted and implemented. > But none of this matters, because Array#last takes an argument :-) > irb(main):008:0> [1,2,3].last(2) > => [2, 3] Sweet! Learn something new every day. That quells the desire for an RCR, because I'm not sure of the theoretical ground for such, your example notwithstanding. For example, consider this: x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] x[-5..3] # -> nil If even *that* returns nil, when *all* numbers in the range are valid indexes, then... Also, there's everybody's favourite example: x[10..15] # -> [] x[11..15] # -> nil I'd rather see 'arr[range]' *always* return an array, no matter the value of 'arr' and 'range'. Thanks, Gavin