Class: CallbackTreeNodeVisitor2
- Inherits:
-
TreeNodeVisitor
- Object
- TreeNodeVisitor
- CallbackTreeNodeVisitor2
- Defined in:
- lib/tree_visitor/tree_node_visitor.rb
Overview
CallbackTreeNodeVisitor
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #enter_treeNode(treeNode) ⇒ Object
- #exit_treeNode(treeNode) ⇒ Object
-
#initialize(root = nil) ⇒ CallbackTreeNodeVisitor2
constructor
A new instance of CallbackTreeNodeVisitor2.
- #onEnterTreeNode(&action) ⇒ Object
- #onVisitLeafNode(&action) ⇒ Object
- #visit_leafNode(leafNode) ⇒ Object
Constructor Details
#initialize(root = nil) ⇒ CallbackTreeNodeVisitor2
Returns a new instance of CallbackTreeNodeVisitor2.
215 216 217 218 219 220 |
# File 'lib/tree_visitor/tree_node_visitor.rb', line 215 def initialize( root = nil ) super() @stack = [] @root = root @stack.push( root ) if root end |
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
213 214 215 |
# File 'lib/tree_visitor/tree_node_visitor.rb', line 213 def root @root end |
Instance Method Details
#enter_treeNode(treeNode) ⇒ Object
230 231 232 233 234 235 236 237 238 239 |
# File 'lib/tree_visitor/tree_node_visitor.rb', line 230 def enter_treeNode( treeNode ) newParentNode = if @stack.empty? nil else @stack.last end newTreeNode = @action_enterTreeNode.call( treeNode, newParentNode ) @root = newTreeNode if @stack.empty? @stack.push( newTreeNode ) end |
#exit_treeNode(treeNode) ⇒ Object
241 242 243 |
# File 'lib/tree_visitor/tree_node_visitor.rb', line 241 def exit_treeNode( treeNode ) @stack.pop end |
#onEnterTreeNode(&action) ⇒ Object
222 223 224 |
# File 'lib/tree_visitor/tree_node_visitor.rb', line 222 def onEnterTreeNode( &action ) @action_enterTreeNode = action end |
#onVisitLeafNode(&action) ⇒ Object
226 227 228 |
# File 'lib/tree_visitor/tree_node_visitor.rb', line 226 def onVisitLeafNode( &action ) @action_visitLeafNode = action end |
#visit_leafNode(leafNode) ⇒ Object
245 246 247 248 |
# File 'lib/tree_visitor/tree_node_visitor.rb', line 245 def visit_leafNode( leafNode ) newParentNode = @stack.last @action_visitLeafNode.call( leafNode, newParentNode ) end |