module Enumerable
def index_by
people.index_by { |person| "#{person.first_name} #{person.last_name}" }
# => { "nextangle" =>
people.index_by(&:login)
element as the value.
Convert an enumerable to a hash, using the block result as the key and the
def index_by if block_given? result = {} each { |elem| result[yield(elem)] = elem } result else to_enum(:index_by) { size if respond_to?(:size) } end end