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:

Merging Trees (collapse)

Instance Method Details

- (Tree::TreeNode) merge(other_tree)

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



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

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

- (Object) merge!(other_tree)

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



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

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