Class: TreeStand::BreadthFirstVisitor
- Inherits:
-
Object
- Object
- TreeStand::BreadthFirstVisitor
- Extended by:
- T::Sig
- Defined in:
- lib/tree_stand/breadth_first_visitor.rb
Overview
Breadth-first traversal through the tree, calling hooks at each stop.
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
10 11 12 |
# File 'lib/tree_stand/breadth_first_visitor.rb', line 10 def initialize(node) @node = node end |
Instance Method Details
#around(node, &block) ⇒ void
This method is abstract.
The default implementation yields to visit all children.
This method returns an undefined value.
32 |
# File 'lib/tree_stand/breadth_first_visitor.rb', line 32 def around(node, &block) = yield |
#on(node) ⇒ void
This method is abstract.
The default implementation does nothing.
This method returns an undefined value.
28 |
# File 'lib/tree_stand/breadth_first_visitor.rb', line 28 def on(node) = nil |
#visit ⇒ T.self_type
Run the visitor on the document and return self. Allows chaining create and visit.
18 19 20 21 22 23 24 |
# File 'lib/tree_stand/breadth_first_visitor.rb', line 18 def visit queue = [@node] while queue.any? visit_node(queue) end self end |