On Sun, 18 Feb 2001, Yasushi Shoji wrote:
> > > >a = "FooBar"
> > > >b = a.split(//)
> > > >b[6,2]          #=> []
> > > >a[6,2]          #=> nil
> > > >anyone knows why this last one returns nil instead of "" (empty string) ?
> > > >matju
> maybe just a typo?
> in rb_ary_entry(), offset/beg is checked with 
>     if (offset < 0 || RARRAY(ary)->len <= offset) {
> 	return Qnil;
>     }

Thanks, but I think the problem is more with String...

in #[index,length], I thought that if #[a,b] returns an array of length
b-k, then #[a+1,b-1] should return an array of length b-k-1.

example:

a[4,4]  #=> ['a','r']
a[5,3]  #=> ['r']
a[6,2]  #=> []
a[7,1]  #=> nil        # b-k-1 < 0

This means that indices valid when you specify a length are the valid
insertion points, which includes length, while indices valid when you
fetch exactly one element excludes length.

This seems fairly logical because that's what #[]= accepts too (without
growing the array with nils)

So I wish String would work similarly (that "FooBar"[6,any] would return
an empty string)

matju