Module: Enumerable

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#group_byObject

1.9 backport



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

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

#sum(initial = 0) ⇒ Object



56
57
58
# File 'lib/ole/support.rb', line 56

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