From 4adfd8e68db88e08ea39c05a14a3375651f058d3 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 19 May 2012 19:33:51 +0530 Subject: copy edits [ci skip] --- .../active_record/associations/collection_proxy.rb | 37 ++++++++++++---------- 1 file changed, 20 insertions(+), 17 deletions(-) (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 a7d7e3a870..fa316a8c9d 100644 --- a/activerecord/lib/active_record/associations/collection_proxy.rb +++ b/activerecord/lib/active_record/associations/collection_proxy.rb @@ -51,8 +51,10 @@ module ActiveRecord # # #, # # #, # # # + # # ] # # person.pets.first # => # + # # person.pets.first(2) # # => [ # # #, @@ -78,8 +80,10 @@ module ActiveRecord # # #, # # #, # # # + # # ] # # person.pets.last # => # + # # person.pets.last(2) # # => [ # # #, @@ -116,7 +120,7 @@ module ActiveRecord # # person.pets.concat([Pet.new(name: 'Brain'), Pet.new(name: 'Benny')]) # person.pets.size # => 5 - + ## # :method: replace # Replace this collection with +other_array+. This will perform a diff @@ -127,17 +131,17 @@ module ActiveRecord # end # # person.pets - # # => [#] + # # => [#] # - # other_pets = [Pet.new(name: 'GorbyPuff', group: 'celebrities'] + # other_pets = [Pet.new(name: 'Puff', group: 'celebrities'] # # person.pets.replace(other_pets) # # person.pets - # # => [#] + # # => [#] # # If the supplied array has an incorrect association type, it raises - # an ActiveRecord::AssociationTypeMismatch error: + # an ActiveRecord::AssociationTypeMismatch error: # # person.pets.replace(["doo", "ggie", "gaga"]) # # => ActiveRecord::AssociationTypeMismatch: Pet expected, got String @@ -156,27 +160,26 @@ module ActiveRecord # # person.pets.size # => 0 # person.pets # => [] - + ## # :method: empty? # Returns true if the collection is empty. - # Equivalent to +size.zero?+. # # class Person < ActiveRecord::Base # has_many :pets # end # # person.pets.count # => 1 - # person.pets.empty? # => false + # person.pets.empty? # => false # # person.pets.delete_all + # # person.pets.count # => 0 # person.pets.empty? # => true ## # :method: any? - # Returns true if the collections is not empty. - # Equivalent to +!collection.empty?+. + # Returns true if the collection is not empty. # # class Person < ActiveRecord::Base # has_many :pets @@ -189,7 +192,7 @@ module ActiveRecord # person.pets.count # => 0 # person.pets.any? # => true # - # Also, you can pass a block to define a criteria. The behaviour + # You can also pass a block to define criteria. The behaviour # is the same, it returns true if the collection based on the # criteria is not empty. # @@ -208,7 +211,7 @@ module ActiveRecord ## # :method: many? - # Returns true if the collection has more than 1 record. + # Returns true if the collection has more than one record. # Equivalent to +collection.size > 1+. # # class Person < ActiveRecord::Base @@ -222,14 +225,14 @@ module ActiveRecord # person.pets.count #=> 2 # person.pets.many? #=> true # - # Also, you can pass a block to define a criteria. The + # You can also pass a block to define criteria. The # behaviour is the same, it returns true if the collection - # based on the criteria has more than 1 record. + # based on the criteria has more than one record. # # person.pets # # => [ - # # #, - # # #, + # # #, + # # #, # # # # # ] # @@ -349,7 +352,7 @@ module ActiveRecord # has_many :pets, dependent: :destroy # end # - # person.pets # => [#] + # person.pets # => [#] # person.pets.clear # => [] # person.pets.size # => 0 # -- cgit v1.2.3