开发者

Array#split behaviour when accessing beyond the array boundry

开发者 https://www.devze.com 2022-12-11 22:04 出处:网络
An irb session is following: >> ar = [:peanute, :butter, :and, :jelly] => [:p开发者_开发问答eanute, :butter, :and, :jelly]

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

精彩评论

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