Skip to content

Commit

Permalink
copy edits [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
vijaydev committed May 19, 2012
1 parent b0f55c6 commit 4adfd8e
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions activerecord/lib/active_record/associations/collection_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ class CollectionProxy < Relation
# # #<Pet id: 1, name: "Fancy-Fancy", person_id: 1>,
# # #<Pet id: 2, name: "Spook", person_id: 1>,
# # #<Pet id: 3, name: "Choo-Choo", person_id: 1>
# # ]
#
# person.pets.first # => #<Pet id: 1, name: "Fancy-Fancy", person_id: 1>
#
# person.pets.first(2)
# # => [
# # #<Pet id: 1, name: "Fancy-Fancy", person_id: 1>,
Expand All @@ -78,8 +80,10 @@ class CollectionProxy < Relation
# # #<Pet id: 1, name: "Fancy-Fancy", person_id: 1>,
# # #<Pet id: 2, name: "Spook", person_id: 1>,
# # #<Pet id: 3, name: "Choo-Choo", person_id: 1>
# # ]
#
# person.pets.last # => #<Pet id: 3, name: "Choo-Choo", person_id: 1>
#
# person.pets.last(2)
# # => [
# # #<Pet id: 2, name: "Spook", person_id: 1>,
Expand Down Expand Up @@ -116,7 +120,7 @@ class CollectionProxy < Relation
#
# 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
Expand All @@ -127,17 +131,17 @@ class CollectionProxy < Relation
# end
#
# person.pets
# # => [#<Pet id: 1, name: "Wy", group: "cats", person_id: 1>]
# # => [#<Pet id: 1, name: "Gorby", group: "cats", person_id: 1>]
#
# other_pets = [Pet.new(name: 'GorbyPuff', group: 'celebrities']
# other_pets = [Pet.new(name: 'Puff', group: 'celebrities']
#
# person.pets.replace(other_pets)
#
# person.pets
# # => [#<Pet id: 2, name: "GorbyPuff", group: "celebrities", person_id: 1>]
# # => [#<Pet id: 2, name: "Puff", group: "celebrities", person_id: 1>]
#
# If the supplied array has an incorrect association type, it raises
# an ActiveRecord::AssociationTypeMismatch error:
# an <tt>ActiveRecord::AssociationTypeMismatch</tt> error:
#
# person.pets.replace(["doo", "ggie", "gaga"])
# # => ActiveRecord::AssociationTypeMismatch: Pet expected, got String
Expand All @@ -156,27 +160,26 @@ class CollectionProxy < Relation
#
# 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
Expand All @@ -189,7 +192,7 @@ class CollectionProxy < Relation
# 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.
#
Expand All @@ -208,7 +211,7 @@ class CollectionProxy < Relation

##
# :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
Expand All @@ -222,14 +225,14 @@ class CollectionProxy < Relation
# 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
# # => [
# # #<Pet name: "GorbyPuff", group: "cats">,
# # #<Pet name: "Wy", group: "cats">,
# # #<Pet name: "Gorby", group: "cats">,
# # #<Pet name: "Puff", group: "cats">,
# # #<Pet name: "Snoop", group: "dogs">
# # ]
#
Expand Down Expand Up @@ -349,7 +352,7 @@ def <<(*records)
# has_many :pets, dependent: :destroy
# end
#
# person.pets # => [#<Pet id: 2, name: "Wy", group: "cats", person_id: 2>]
# person.pets # => [#<Pet id: 2, name: "Gorby", group: "cats", person_id: 2>]
# person.pets.clear # => []
# person.pets.size # => 0
#
Expand Down

0 comments on commit 4adfd8e

Please sign in to comment.