From: Matthew Berg Date: 2003-11-12T07:04:54+09:00 Subject: Re: Array#slice oddity... On Tue, 2003-11-11 at 16:45, Joel VanderWerf wrote: > Matthew Berg wrote: > > It appears that if you use slice or slice! with a length argument, it > > returns an array even if the index is out of range: > > > > irb(main):001:0> a = [] > > => [] > > irb(main):002:0> b = a.slice(0) > > => nil > > irb(main):003:0> b = a.slice(0,1) > > => [] > > Shouldn't a[0] and a[0,1][0] return the same value? That they do... irb(main):002:0> a[0] => nil irb(main):003:0> a[0,1][0] => nil Another thing I noticed is that this behaviour is only exhibited if the start index is 0: irb(main):004:0> a[0,1] => [] irb(main):005:0> a[1,2] => nil The same thing happens with ranges: irb(main):006:0> a[0..1] => [] irb(main):007:0> a[1..2] => nil -- Matthew Berg