Array.last
Signature
array.last #=> object or nil
array.last(number) #=> new_array
array.last returns the last element of array or it returns nil ifarray is empty. array.last(number) returns the last number elements ofarray or it returns an empty array if array is empty.
Examples
a = ["a", "b", "c", "d", "e", "f"]
a.last #=> "f"
[].last #=> nil
a.last(0) #=> []
a.last(1) #=> ["f"]
a.last(4) #=> ["c", "d", "e", "f"]
a.last(99) #=> ["a", "b", "c", "d", "e", "f"]
[].last(10) #=> []
Documentation Reference
Ruby version 1.8.6
- Log in to post comments
