访问数组边界以外的数组#拆分行为

时间:2009-11-21 05:42:57

标签: ruby

irb会话如下:

>> ar = [:peanute, :butter, :and, :jelly]
=> [:peanute, :butter, :and, :jelly]
>> ar[0, 1]
=> [:peanute]
>> ar[4, 1]
=> []
>> ar[5, 1]
=> nil

为什么ar [4,1]不像ar [5,1]那样返回nil?有人会解释这种行为吗?

1 个答案:

答案 0 :(得分:2)

documentation中提到了这一特例。