From: jsuntheimer@... (Jake) Date: 2001-11-10T09:48:53+09:00 Subject: [ruby-talk:24812] Re: Strange behaviour of Array#[] matz@ruby-lang.org (Yukihiro Matsumoto) wrote in message news:<1005325837.252683.3581.nullmailer@ev.netlab.jp>... > Hi, > > In message "[ruby-talk:24773] Re: Strange behaviour of Array#[]" > on 01/11/10, "Lyle Johnson" writes: > > |> I believe it's for consistency with Strings: > | > |This is still pretty squirrelly to me, but hey, it's not my language ;) > > For these methods, each index points at the edge between elements. > > Suppose we have array = [0, 1, 2, 3], > > -4 -3 -2 -1 > +---+---+---+---+ > | 0 | 1 | 2 | 3 | > +---+---+---+---+ > 0 1 2 3 4 > > when the index is not pointing existing edge, array[idx, n] returns > nil (in this case, idx < -4 or 4 < idx). > > Index 4 points the last edge of the array, so it does return a > subarray, which is an empty array since there's no element after the > last edge. > > matz. .... and everyone nodded.