1
2
3
4
5
6
7
8
9
10
11
12
13
14
module Enumerable

  undef :sum
  def sum(identity = 0, &block)
    return identity unless size > 0

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

end