Module: Enumerable

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#group_byObject

1.9 backport



40
41
42
43
44
# File 'lib/ole/support.rb', line 40

def group_by
	hash = Hash.new { |h, key| h[key] = [] }
	each { |item| hash[yield(item)] << item }
	hash
end

#sum(initial = 0) ⇒ Object



48
49
50
# File 'lib/ole/support.rb', line 48

def sum initial=0
	inject(initial) { |a, b| a + b }
end