method

last

Importance_1
Ruby latest stable (v1_8_6_287) - 1 note - Class: Array
last(...) public

Returns the last element(s) of self. If the array is empty, the first form returns nil.

   [ "w", "x", "y", "z" ].last   #=> "z"
Show source
Register or log in to add new notes.
August 18, 2008
0 thanks

Last element of an array alternative

You can also access the last element of an array with -1

 [ "w", "x", "y", "z" ][-1]  #=> "z"