Module: Tree::Utils::TreeMergeHandler

Included in:
TreeNode
Defined in:
lib/tree/utils/tree_merge_handler.rb

Overview

Provides utility methods to merge two TreeNode based trees.

Since:

  • 0.9.0

Merging Trees collapse

Instance Method Details

#merge(other_tree) ⇒ Tree::TreeNode

Merge two trees that share the same root node and returns a new tree.

The new tree contains the contents of the merge between other_tree and self. Duplicate nodes (coming from other_tree) will NOT be overwritten in self.

Parameters:

Returns:

Raises:

  • (TypeError)

    This exception is raised if other_tree is not a TreeNode.

  • (ArgumentError)

    This exception is raised if other_tree does not have the same root node as self.

Author:

Since:

  • 0.9.0



63
64
65
66
# File 'lib/tree/utils/tree_merge_handler.rb', line 63

def merge(other_tree)
  check_merge_prerequisites(other_tree)
  merge_trees(self.root.dup, other_tree.root)
end

#merge!(other_tree) ⇒ Object

Merge in another tree (that shares the same root node) into this tree. Duplicate nodes (coming from other_tree) will NOT be overwritten in self.

Parameters:

Raises:

  • (TypeError)

    This exception is raised if other_tree is not a TreeNode.

  • (ArgumentError)

    This exception is raised if other_tree does not have the same root node as self.

Author:

Since:

  • 0.9.0



81
82
83
84
# File 'lib/tree/utils/tree_merge_handler.rb', line 81

def merge!(other_tree)
  check_merge_prerequisites( other_tree )
  merge_trees( self.root, other_tree.root )
end