Enumerable#sum
module Enumerable
def sum(*args)
inject(*args) { |sum, x| sum + x }
end
end
[1, 2, 3].sum # => 6
(1..100).sum # => 5050
%w(foo bar).sum # => "foobar"
[ ].sum(0) # => 0
[ 1 ].sum(2) # => 3
Ah, the joy of dynamic typing. Quack! What?