Module: Enumerable
- Included in:
- Ole::Storage::DirClass::Dir, Ole::Storage::MetaData, Ole::Types::PropertySet, Ole::Types::PropertySet::Section
- Defined in:
- lib/ole/support.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#group_by ⇒ Object
1.9 backport.
- #sum(initial = 0) ⇒ Object
Instance Method Details
#group_by ⇒ Object
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 |