为什么 3,4 时候返回时空数组,5 就返回了 nil?
array = [:peanut, :butter, :and, :jelly] => [:peanut, :butter, :and, :jelly] 2.1.2 :055 > array[3,0] => [] 2.1.2 :056 > array[4,0] => [] 2.1.2 :057 > array[5,0] => nil 2.1.2 :058 >
嗯,一个坑
关于Array#slice an empty array is returned when the starting index for an element range is at the end of the array. Returns nil if the index (or starting index) are out of range. 来源 ruby-doc
Array#slice
#2 楼 @erithair 多谢!