class IHash
Public Class Methods
stringify(obj)
click to toggle source
# File lib/i_hash.rb, line 38 def stringify(obj) if obj.is_a? Hash return obj.inject({}) do |memo, (k, v)| memo.tap { |m| m[k.to_s] = stringify(v) } end elsif obj.is_a? Array return obj.map { |memo| stringify(memo) } end obj end
symbolize(obj)
click to toggle source
# File lib/i_hash.rb, line 27 def symbolize(obj) if obj.is_a? Hash return obj.inject({}) do |memo, (k, v)| memo.tap { |m| m[k.to_sym] = symbolize(v) } end elsif obj.is_a? Array return obj.map { |memo| symbolize(memo) } end obj end
Public Instance Methods
compare(other_hash)
click to toggle source
# File lib/i_hash.rb, line 10 def compare(other_hash) current_hash = IHash.symbolize(self) other_hash = IHash.symbolize(other_hash) (current_hash.keys | other_hash.keys).each_with_object({}) do |k, diff| current_hash_key = current_hash[k] other_hash_key = other_hash[k] if current_hash_key != other_hash_key diff[k] = [current_hash_key, other_hash_key] next unless current_hash_key.is_a?(Hash) && other_hash_key.is_a?(Hash) diff[k] = deep_diff(current_hash_key, other_hash_key) end diff end end
stringify_keys()
click to toggle source
# File lib/i_hash.rb, line 6 def stringify_keys IHash.stringify(self) end
symbolize_keys()
click to toggle source
# File lib/i_hash.rb, line 2 def symbolize_keys IHash.symbolize(self) end