From b0f55c68887930ada279302cceaf10e2ca67de52 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Sat, 19 May 2012 08:20:49 -0500 Subject: add CollectionProxy#last documentation --- .../active_record/associations/collection_proxy.rb | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb index 401019e1f3..a7d7e3a870 100644 --- a/activerecord/lib/active_record/associations/collection_proxy.rb +++ b/activerecord/lib/active_record/associations/collection_proxy.rb @@ -63,6 +63,33 @@ module ActiveRecord # another_person_without.pets.first # => nil # another_person_without.pets.first(3) # => [] + ## + # :method: last + # Returns the last record, or the last +n+ records, from the collection. + # If the collection is empty, the first form returns nil, and the second + # form returns an empty array. + # + # class Person < ActiveRecord::Base + # has_many :pets + # end + # + # person.pets + # # => [ + # # #, + # # #, + # # # + # + # person.pets.last # => # + # person.pets.last(2) + # # => [ + # # #, + # # # + # # ] + # + # another_person_without.pets # => [] + # another_person_without.pets.last # => nil + # another_person_without.pets.last(3) # => [] + ## # :method: concat # Add one or more records to the collection by setting their foreign keys -- cgit v1.2.3