module Gemmy::Patches::ArrayPatch::InstanceMethods::KeyBy

Public Class Methods

autotest() click to toggle source
# 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

Public Instance Methods

key_by() { |v| ... } click to toggle source

facets

# 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