lib/hash_ext/normalized.rb in hash_ext-0.5.0 vs lib/hash_ext/normalized.rb in hash_ext-0.6.0
- old
+ new
@@ -51,9 +51,16 @@
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|
+ target ? target[key] : nil
+ end
+ end
+
def to_h
each_with_object({}) do |(key, value), hash|
hash[key] = value_to_h value
end
end
\ No newline at end of file