Skip to content

Commit

Permalink
revises the rdoc of #average according to 5f3bd55, and realigns when …
Browse files Browse the repository at this point in the history
…clauses
  • Loading branch information
fxn committed May 12, 2010
1 parent 5f3bd55 commit 7321a3a
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions activerecord/lib/active_record/relation/calculations.rb
Expand Up @@ -45,9 +45,8 @@ def count(column_name = nil, options = {})
calculate(:count, column_name, options) calculate(:count, column_name, options)
end end


# Calculates the average value on a given column. The value is returned as # Calculates the average value on a given column. Returns +nil+ if there's
# a float, or +nil+ if there's no row. See +calculate+ for examples with # no row. See +calculate+ for examples with options.
# options.
# #
# Person.average('age') # => 35.8 # Person.average('age') # => 35.8
def average(column_name, options = {}) def average(column_name, options = {})
Expand Down Expand Up @@ -241,8 +240,8 @@ def column_for(field)
def type_cast_calculated_value(value, column, operation = nil) def type_cast_calculated_value(value, column, operation = nil)
if value.is_a?(String) || value.nil? if value.is_a?(String) || value.nil?
case operation case operation
when 'count' then value.to_i when 'count' then value.to_i
when 'sum' then type_cast_using_column(value || '0', column) when 'sum' then type_cast_using_column(value || '0', column)
when 'average' then value.try(:to_d) when 'average' then value.try(:to_d)
else type_cast_using_column(value, column) else type_cast_using_column(value, column)
end end
Expand Down

0 comments on commit 7321a3a

Please sign in to comment.