Sha256: 8864a2d2d0d2ba6a5ce9e5634cae619ad078488a2f33fdee8a8e7635b93bb81f

Contents?: true

Size: 454 Bytes

Versions: 1

Compression:

Stored size: 454 Bytes

Contents

require_relative '../hash/putbang'

module Enumerable

  # Converts an +Enumerable+ into a +Hash+ by using its elements as keys
  # and extracting values from each.
  #
  # @yield [elem] extracts a value
  # @yieldparam elem element from the +Enumerable+
  # @yieldreturn value to associate with the +elem+ key
  # @return [Hash] hash with the +Enumerable+'s elements as keys
  def index_to()
    self.reduce({}){|h, k| h.put!(k, (yield k)) }
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
casual_support-2.0.0 lib/casual_support/enumerable/index_to.rb