Possible Duplicate:
Array slicing in Ruby: looking for explanation for illogical behaviour (taken from Rubykoans.com)
I have an Array 'a'
a = [ "a", "b", "c", "d", "e" ]
In irb i have done following experiment
irb(main):003:0> a[4,1]
=> ["e"]
irb(main):004:0> a[5,1]
=> []
irb(main):005:0> a[6,1]
=> nil
irb(main):006:0>
My question is,
in case of a[5,1] why it return an empty array instead of 'nil'? is this behavior expected? if so why?
In Ruby doc it is marked as '# special cases', Unfortunately, they are not explained why it works this way?
I have notice same problem and also solution in two place of Stack overflow, first and second In first one it is explained as 'slice does not identify the element but places between elements'
In second one it is explained as a bug of ruby implementation.
what will be proper explanation of this problem?