Module: Enumerable

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#group_byObject

1.9 backport



44
45
46
47
48
# File 'lib/ole/support.rb', line 44

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

#sum(initial = 0) ⇒ Object



52
53
54
# File 'lib/ole/support.rb', line 52

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