Mega Code Archive

 
Categories / Ruby / Array
 

The last element in the array is -1, the previous one -2, the previous one -3

array = ["Hello", "there", "AAA", 1, 2, 3] puts array[-1]            #prints 3 puts array[-2]            #prints 2 puts array[-3]            #prints 1