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) ⇒ void abstract
- #initialize(node) ⇒ void constructor
- #on(node) ⇒ void abstract
-
#visit ⇒ T.self_type
Run the visitor on the document and return self.
Constructor Details
#initialize(node) ⇒ void
67 68 69 |
# File 'lib/tree_stand/visitor.rb', line 67 def initialize(node) @node = node end |
Instance Method Details
#around(node, &block) ⇒ void
The default implementation yields to visit all children.
This method returns an undefined value.
105 |
# File 'lib/tree_stand/visitor.rb', line 105 def around(node, &block) = yield |
#on(node) ⇒ void
The default implementation does nothing.
This method returns an undefined value.
87 |
# File 'lib/tree_stand/visitor.rb', line 87 def on(node) = nil |
#visit ⇒ T.self_type
Run the visitor on the document and return self. Allows chaining create and visit.
75 76 77 78 |
# File 'lib/tree_stand/visitor.rb', line 75 def visit visit_node(@node) self end |