Class: CloneTreeNodeVisitor

Inherits:
TreeNodeVisitor show all
Defined in:
lib/tree_visitor/tree_node_visitor.rb

Overview

Esempio Clona un TreeNode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCloneTreeNodeVisitor

Returns a new instance of CloneTreeNodeVisitor.



137
138
139
140
141
# File 'lib/tree_visitor/tree_node_visitor.rb', line 137

def initialize
  super
  @clonedRoot = nil
  @stack = []
end

Instance Attribute Details

#clonedRootObject (readonly)

Returns the value of attribute clonedRoot.



135
136
137
# File 'lib/tree_visitor/tree_node_visitor.rb', line 135

def clonedRoot
  @clonedRoot
end

Instance Method Details

#enter_treeNode(treeNode) ⇒ Object



143
144
145
146
147
148
149
150
151
# File 'lib/tree_visitor/tree_node_visitor.rb', line 143

def enter_treeNode( treeNode )
  if @stack.empty?
    clonedTreeNode = TreeNode.new( treeNode.name )
    @clonedRoot = clonedTreeNode
  else
    clonedTreeNode = TreeNode.new( treeNode.name, @stack.last )
  end
  @stack.push( clonedTreeNode )
end

#exit_treeNode(treeNode) ⇒ Object



153
154
155
# File 'lib/tree_visitor/tree_node_visitor.rb', line 153

def exit_treeNode( treeNode )
  @stack.pop
end

#visit_leafNode(leafNode) ⇒ Object



157
158
159
# File 'lib/tree_visitor/tree_node_visitor.rb', line 157

def visit_leafNode( leafNode )
  clonedLeafNode = LeafNode.new( leafNode.name, @stack.last )
end