Class: TreeRb::CloneTreeNodeVisitor
- Inherits:
-
Object
- Object
- TreeRb::CloneTreeNodeVisitor
- Defined in:
- lib/tree_rb/visitors/clone_tree_node_visitor.rb
Overview
Clone a tree_node, nodes are duplicated. Node content are not duplicated!
Instance Attribute Summary collapse
-
#cloned_root ⇒ Object
readonly
Contains the cloned tree node after the visit.
Instance Method Summary collapse
-
#cannot_enter_node(tree_node, error) ⇒ Object
called when the tree node is not accessible or an exception is raise when the node is accessed.
- #enter_node(tree_node) ⇒ Object
- #exit_node(tree_node) ⇒ Object
-
#initialize ⇒ CloneTreeNodeVisitor
constructor
A new instance of CloneTreeNodeVisitor.
- #visit_leaf(leaf_node) ⇒ Object
Constructor Details
#initialize ⇒ CloneTreeNodeVisitor
Returns a new instance of CloneTreeNodeVisitor.
14 15 16 17 |
# File 'lib/tree_rb/visitors/clone_tree_node_visitor.rb', line 14 def initialize @cloned_root = nil @stack = [] end |
Instance Attribute Details
#cloned_root ⇒ Object (readonly)
Contains the cloned tree node after the visit
12 13 14 |
# File 'lib/tree_rb/visitors/clone_tree_node_visitor.rb', line 12 def cloned_root @cloned_root end |
Instance Method Details
#cannot_enter_node(tree_node, error) ⇒ Object
called when the tree node is not accessible or an exception is raise when the node is accessed
36 37 |
# File 'lib/tree_rb/visitors/clone_tree_node_visitor.rb', line 36 def cannot_enter_node( tree_node, error) end |
#enter_node(tree_node) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/tree_rb/visitors/clone_tree_node_visitor.rb', line 19 def enter_node( tree_node ) if @stack.empty? cloned_tree_node = TreeNode.new( tree_node.content ) @cloned_root = cloned_tree_node else cloned_tree_node = TreeNode.new( tree_node.content, @stack.last ) end @stack.push( cloned_tree_node ) end |
#exit_node(tree_node) ⇒ Object
29 30 31 |
# File 'lib/tree_rb/visitors/clone_tree_node_visitor.rb', line 29 def exit_node( tree_node ) @stack.pop end |