Skip to content

Commit bfe28e2

Browse files
Reword block form doc for AR::Calculations#{count,sum} [ci-skip]
1 parent 6ebe6f3 commit bfe28e2

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

activerecord/lib/active_record/relation/calculations.rb

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ def truncate(name)
8282
# Note: not all valid {Relation#select}[rdoc-ref:QueryMethods#select] expressions are valid +count+ expressions. The specifics differ
8383
# between databases. In invalid cases, an error from the database is thrown.
8484
#
85-
# When given a block, loads all records in the relation, if the relation
86-
# hasn't been loaded yet. Calls the block with each record in the relation.
87-
# Returns the number of records for which the block returns a truthy value.
85+
# When given a block, calls the block with each record in the relation and
86+
# returns the number of records for which the block returns a truthy value.
8887
#
8988
# Person.count { |person| person.age > 21 }
9089
# # => counts the number of people older that 21
9190
#
92-
# Note: If there are a lot of records in the relation, loading all records
93-
# could result in performance issues.
91+
# If the relation hasn't been loaded yet, calling +count+ with a block will
92+
# load all records in the relation. If there are a lot of records in the
93+
# relation, loading all records could result in performance issues.
9494
def count(column_name = nil)
9595
if block_given?
9696
unless column_name.nil?
@@ -159,16 +159,15 @@ def async_maximum(column_name)
159159
#
160160
# Person.sum(:age) # => 4562
161161
#
162-
# When given a block, loads all records in the relation, if the relation
163-
# hasn't been loaded yet. Calls the block with each record in the relation.
164-
# Returns the sum of +initial_value_or_column+ and the block return
165-
# values:
162+
# When given a block, calls the block with each record in the relation and
163+
# returns the sum of +initial_value_or_column+ plus the block return values:
166164
#
167165
# Person.sum { |person| person.age } # => 4562
168166
# Person.sum(1000) { |person| person.age } # => 5562
169167
#
170-
# Note: If there are a lot of records in the relation, loading all records
171-
# could result in performance issues.
168+
# If the relation hasn't been loaded yet, calling +sum+ with a block will
169+
# load all records in the relation. If there are a lot of records in the
170+
# relation, loading all records could result in performance issues.
172171
def sum(initial_value_or_column = 0, &block)
173172
if block_given?
174173
map(&block).sum(initial_value_or_column)

0 commit comments

Comments
 (0)