module Nuggets::Array::HashifyMixin

Public Instance Methods

hashify(value = nil, &block) click to toggle source
# File lib/nuggets/array/hashify_mixin.rb, line 31
def hashify(value = nil, &block)
  block ||= lambda { |key| [key, key] }

  hash = case value
    when ::Hash then value
    when ::Proc then ::Hash.new(&value)
    else             ::Hash.new(value)
  end

  each { |key| hash.store(*block[key]) }

  hash
end