[LRUG] Array.slice question

Tom Stuart tom at experthuman.com
Wed Sep 7 01:45:49 PDT 2011


On 7 Sep 2011, at 09:29, Michael Pavling wrote:
> when I call x[3,0] I *expect* it to return
> nil (as the starting index is out of range), but it returns an empty
> array:
>>> x[3,0]
>  => []

Not really an explanation, but this is just how rb_ary_subseq works[1]. It's noted as a special case in the Array#slice documentation[2].

Cheers,
-Tom

[1] https://github.com/ruby/ruby/blob/trunk/array.c#L952
[2] http://ruby-doc.org/core/classes/Array.html#M000267


More information about the Chat mailing list