Module: Tree::Utils::TreeMergeHandler

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

Overview

Handles merging of two 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



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

def merge(other_tree)
  check_merge_prerequisites(other_tree)
  merge_trees(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



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

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