Class: TreeStand::Visitor
- Inherits:
-
Object
- Object
- TreeStand::Visitor
- Extended by:
- T::Sig
- Defined in:
- lib/tree_stand/visitor.rb
Overview
Depth-first traversal through the tree, calling hooks at each stop.
Hooks are language dependent and are defined by creating methods on the visitor with the form ‘on_*` or `around_*`, where `*` is Node#type.
-
Hooks prefixed with ‘on_*` are called before visiting a node.
-
Hooks prefixed with ‘around_*` must `yield` to continue visiting child nodes.
You can also define default hooks by implementing an #on or #around method to call when visiting each node.
Direct Known Subclasses
Instance Method Summary collapse
- #around(node, &block) ⇒ Object
-
#initialize(node) ⇒ Visitor
constructor
A new instance of Visitor.
- #on(node) ⇒ Object
- #visit ⇒ Object
Constructor Details
#initialize(node) ⇒ Visitor
Returns a new instance of Visitor.
67 68 69 |
# File 'lib/tree_stand/visitor.rb', line 67 def initialize(node) @node = node end |
Instance Method Details
#around(node, &block) ⇒ Object
105 |
# File 'lib/tree_stand/visitor.rb', line 105 def around(node, &block) = yield |
#on(node) ⇒ Object
87 |
# File 'lib/tree_stand/visitor.rb', line 87 def on(node) = nil |
#visit ⇒ Object
75 76 77 78 |
# File 'lib/tree_stand/visitor.rb', line 75 def visit visit_node(@node) self end |