first

enum.first â obj or nil
enum.first(n) â an_array
Instance Public methods

Returns the first element, or the first n elements, of the enumerable. If the enumerable is empty, the first form returns nil, and the second form returns an empty array.

%w[foo bar baz].first     #=> "foo"
%w[foo bar baz].first(2)  #=> ["foo", "bar"]
%w[foo bar baz].first(10) #=> ["foo", "bar", "baz"]
[].first                  #=> nil
doc_ruby_on_rails
2015-04-05 00:21:33
Comments
Leave a Comment

Please login to continue.