A negative index is assumed to be relative to the end of the array---that is, an index of -1 indicates the last element of the array, -2 is the next to last element in the array, and so on.
Check these examples:
# Teaching Example
irb(main):001:0> a = [1, 2, 3] => [1, 2, 3] irb(main):002:0> a[-2] => 2
# Practical Example
Easy way to get the
You can found more detailed info here Ruby Docs