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
90 91 92 |
# File 'lib/gemmy/patches/array_patch.rb', line 90 def self.autotest [1,2,3].key_by { |v| v % 2 } == { 1 => [1, 3], 0 => [2] } end |
Instance Method Details
#key_by ⇒ Object
facets
82 83 84 85 86 87 88 89 |
# File 'lib/gemmy/patches/array_patch.rb', line 82 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 |