class HashHelper

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/hash_helper.rb, line 2
def self.new
  @instance ||= super
end

Public Instance Methods

deep_merge(hash, other_hash) click to toggle source
# File lib/hash_helper.rb, line 11
def deep_merge(hash, other_hash)
  hash.merge(other_hash) do |key, oldval, newval|
    oldval = oldval.to_hash if oldval.respond_to?(:to_hash)
    newval = newval.to_hash if newval.respond_to?(:to_hash)
    oldval.class.to_s == 'Hash' && newval.class.to_s == 'Hash' ? deep_merge(oldval, newval) : newval
  end
end
hasherize(array, &block) click to toggle source
# File lib/hash_helper.rb, line 6
def hasherize(array, &block)
  block ||= ->(e) { e }
  Hash[*array.map{|e| [e, block.call(e)] }.flatten]
end