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