Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Carlson committed Jul 6, 2010
1 parent ea24a2f commit bb87980
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/classifier/extensions/vector.rb
Expand Up @@ -7,9 +7,15 @@
require 'mathn'

class Array
def sum
inject(0) { |sum,term| sum += term }.to_f
end
def sum(identity = 0, &block)
return identity unless size > 0

if block_given?
map(&block).sum
else
inject { |sum, element| sum + element }.to_f
end
end
end

class Vector
Expand Down

0 comments on commit bb87980

Please sign in to comment.