Permalink
Browse files

* Translate::Keys.deep_delete to delete the node in a deep hash speci…

…fied by the given full translation key
  • Loading branch information...
1 parent e726249 commit 2d37f570d419726ad848f62157f866e34ca8069f @ozataman committed Aug 6, 2009
Showing with 18 additions and 0 deletions.
  1. +18 −0 lib/translate/keys.rb
View
@@ -48,6 +48,24 @@ def self.to_deep_hash(hash)
deep_hash
end
end
+
+ def self.deep_delete!(hash, key)
+ key_path = key.split(".")
+
+ parent_node = key_path.inject(hash) do |node, key|
+ if node[key].is_a?(Hash)
+ node[key]
+ else
+ node
+ end
+ end
+
+ # delete the deep key
+ parent_node.delete(key_path.last)
+
+ # return the modified hash
+ hash
+ end
# deep_merge by Stefan Rusterholz, see http://www.ruby-forum.com/topic/142809
def self.deep_merge!(hash1, hash2)

0 comments on commit 2d37f57

Please sign in to comment.