lib/key_tree/tree.rb in key_tree-0.2.0 vs lib/key_tree/tree.rb in key_tree-0.3.0

- old
+ new

@@ -1,10 +1,11 @@ require 'key_tree/path' - +require 'key_tree/meta_data' module KeyTree # A tree of key-value lookup tables (hashes) class Tree < Hash + include MetaData # # KeyTree::Tree.new(+hash+) # # Initialize a new KeyTree from nested Hash:es # @@ -67,11 +68,18 @@ end # The merging of trees needs some extra consideration; due to the # nature of key paths, prefix conflicts must be deleted # - def merge(other) + def merge!(other) + other = Tree[other] unless other.is_a?(Tree) delete_if { |key, _| other.conflict?(key) } super end + alias << merge! + + def merge(other) + dup.merge!(other) + end + alias + merge end end