Class: TreeRb::DepthTreeNodeVisitor
- Inherits:
-
Object
- Object
- TreeRb::DepthTreeNodeVisitor
- Defined in:
- lib/tree_rb/visitors/depth_tree_node_visitor.rb
Overview
Simple visitor: show how calculate the depth of a tree
Instance Attribute Summary collapse
-
#depth ⇒ Object
readonly
< BasicTreeNodeVisitor.
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 ⇒ DepthTreeNodeVisitor
constructor
A new instance of DepthTreeNodeVisitor.
- #visit_leaf(leaf_node) ⇒ Object
Constructor Details
#initialize ⇒ DepthTreeNodeVisitor
Returns a new instance of DepthTreeNodeVisitor.
10 11 12 |
# File 'lib/tree_rb/visitors/depth_tree_node_visitor.rb', line 10 def initialize @depth = 0 end |
Instance Attribute Details
#depth ⇒ Object (readonly)
< BasicTreeNodeVisitor
8 9 10 |
# File 'lib/tree_rb/visitors/depth_tree_node_visitor.rb', line 8 def depth @depth 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
25 26 |
# File 'lib/tree_rb/visitors/depth_tree_node_visitor.rb', line 25 def cannot_enter_node( tree_node, error) end |
#enter_node(tree_node) ⇒ Object
14 15 16 |
# File 'lib/tree_rb/visitors/depth_tree_node_visitor.rb', line 14 def enter_node( tree_node ) @depth += 1 end |
#exit_node(tree_node) ⇒ Object
18 19 20 |
# File 'lib/tree_rb/visitors/depth_tree_node_visitor.rb', line 18 def exit_node( tree_node ) @depth -= 1 end |
#visit_leaf(leaf_node) ⇒ Object
28 29 |
# File 'lib/tree_rb/visitors/depth_tree_node_visitor.rb', line 28 def visit_leaf( leaf_node ) end |