Mega Code Archive

 
Categories / Ruby / Array
 

Use negative array indices in Ruby

# Negative indices count from the end of the array back to the beginning of the array.  array = ["Hello", "there", "AAA", 1, 2, 3] puts array[-1]            #prints 3