开发者

Array#split behaviour when accessing beyond the array boundry

An irb session is following:

>> ar = [:peanute, :butter, :and, :jelly]
=> [:p开发者_开发问答eanute, :butter, :and, :jelly]
>> ar[0, 1]
=> [:peanute]
>> ar[4, 1]
=> []
>> ar[5, 1]
=> nil

Why ar[4, 1] does not return nil just like ar[5, 1]? Would someone explain this behaviour?


This is mentioned in the documentation as a special case.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜