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有人能解释一下这种行为吗?

最佳答案

这在documentation中作为特例提到。

关于ruby - 超出数组边界访问时的Array#split行为,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1774627/

10-13 04:44