lib/hash_ext/normalized.rb in hash_ext-0.6.0 vs lib/hash_ext/normalized.rb in hash_ext-0.6.1
- old
+ new
@@ -52,14 +52,14 @@
def fetch(key, *args, &block)
super normalize_key(key), *args, &block
end
def dig(*keys)
- normalized_key = keys.map { |k| normalize_key(k) }
- normalized_key.inject(self) do |target, key|
+ normalized_keys = keys.map { |k| normalize_key(k) }
+ normalized_keys.inject(self) do |target, key|
target ? target[key] : nil
- end
+ end
end
def to_h
each_with_object({}) do |(key, value), hash|
hash[key] = value_to_h value
@@ -71,11 +71,13 @@
def normalize_key(key)
@normalization_block.call key
end
def normalize_value(value)
- if value.kind_of? Hash
- self.class.new value
+ if value.is_a? self.class
+ value
+ elsif value.kind_of? Hash
+ self.class.new value, &@normalization_block
elsif value.kind_of? Array
value.map { |v| normalize_value v }
else
value
end
\ No newline at end of file