I'm going through Ruby Koans as a way to learn Ruby. I'm having trouble understanding what the difference is between the two test cases in red, below, as to why the first is an empty array while the latter is nil. Seems to me like they should be the same (whichever result), as both having an offset beyond the last element of the array. Or is only one past the last element a special case?
def test_slicing_arrays
array = [:peanut, :butter, :and, :jelly]
assert_equal [:peanut], array[0,1]
assert_equal [:peanut, :butter], array[0,2]
assert_equal [:and, :jelly], array[2,2]
assert_equal [:and, :jelly], array[2,20]
[COLOR="#FF0000"]assert_equal [], array[4,0][/COLOR]
assert_equal [], array[4,100]
[COLOR="#FF0000"]assert_equal nil, array[5,0][/COLOR]
end
Thanks.