Module: Enumerable

Defined in:
lib/pdf/core.rb

Instance Method Summary collapse

Instance Method Details

#sum(identity = 0, &block) ⇒ Object

borrowed from active support. No need to pull that entire beast in as a dependency



45
46
47
48
49
50
51
52
53
# File 'lib/pdf/core.rb', line 45

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

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