lib/esse/primitives/hash_utils.rb in esse-0.2.3 vs lib/esse/primitives/hash_utils.rb in esse-0.2.4

- old
+ new

@@ -4,9 +4,20 @@ # The idea here is to add useful methods to the ruby standard objects without # monkey patching them module HashUtils module_function + def deep_dup(hash) + hash.each_with_object({}) do |(key, value), result| + result[key] = \ + if value.is_a?(Hash) + deep_dup(value) + else + value + end + end + end + def deep_transform_keys(hash, &block) hash.each_with_object({}) do |(key, value), result| result[yield(key)] = \ if value.is_a?(Hash) deep_transform_keys(value, &block)