Module: Enumerable

Defined in:
lib/alib-0.5.1/stdext.rb

Instance Method Summary collapse

Instance Method Details

#product(n = 1) ⇒ Object



106
107
108
109
# File 'lib/alib-0.5.1/stdext.rb', line 106

def product n = 1
  return 0 if empty?
  inject(n){|n,i| n *= i}
end

#sum(n = 0) ⇒ Object



103
104
105
# File 'lib/alib-0.5.1/stdext.rb', line 103

def sum n = 0
  inject(n){|n,i| n += i}
end