If I have an array a:
a[a.length] returns nil. Good.a[a.length, x] returns []. Good.
To begin with, this case is a special case in Ruby.
This special case also has an explanation to it:
There is a point of difference when you speak about indexing an array, and slicing it.
Indexing an array means to have an unique Position which helps you access the value at a given Index.
Slicing on the other hand means to "cut" between two points (P.S points here are index)
Consider this:
array = [Ruby, PHP, JS, HTML, CSS]
Indexing in this case will be:
array = [Ruby, PHP, JS, HTML, CSS]
Index = 0. 1. 2. 3. 4.
Slicing in the same case will be:
array = [Ruby, PHP, JS, HTML, CSS]
Slice = 0. 1. 2. 3. 4. 5.
Hence:
array[5,n] #[] i.e. you get an empty array.
array[6,n] #nil i.e. NIL
Reference