Module: Gemmy::Patches::ArrayPatch::InstanceMethods::KeyBy
- Defined in:
- lib/gemmy/patches/array_patch.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#key_by ⇒ Object
facets.
Class Method Details
.autotest ⇒ Object
103 104 105 |
# File 'lib/gemmy/patches/array_patch.rb', line 103 def self.autotest [1,2,3].key_by { |v| v % 2 } == { 1 => [1, 3], 0 => [2] } end |
Instance Method Details
#key_by ⇒ Object
facets
95 96 97 98 99 100 101 102 |
# File 'lib/gemmy/patches/array_patch.rb', line 95 def key_by return to_enum(:key_by) unless block_given? h = Hash.new { |h,k| h[k] = [] } each do |v| h[yield(v)] << v end return h end |