Matthew Berg
11/11/2003 10:47:00 PM
On Tue, 2003-11-11 at 17:09, Hal Fulton wrote:
> Matthew Berg wrote:
> > 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
>
> I think it depends on how far off the end of the
> array you go.
>
> x = [1,2,3]
> x[3,3] # []
> x[4,4] # nil
Just to clarify, "how far off the end" in this case seems to be
determined solely by the start value, not the length:
x[3,1000000000] # []
x[4,1] # nil
So I guess it gives you an empty array if you request a start index one
past the end of the array, but only if you didn't specify a length.
> There's a kind of logic to it, but it requires long and
> hard thought (for me, anyway). Search the archives.
I'll take a look to see if I can find anything on it. One way or
another I can work around it even if it seems a bit counterintuitive.
:)
--
Matthew Berg <galt@gothpoodle.com>