Class: TreeStand::BreadthFirstVisitor

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(node) ⇒ void

Parameters:



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.

Parameters:



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.

Parameters:



28
# File 'lib/tree_stand/breadth_first_visitor.rb', line 28

def on(node) = nil

#visitT.self_type

Run the visitor on the document and return self. Allows chaining create and visit.

Examples:

visitor = CountingVisitor.new(node, :predicate).visit

Returns:

  • (T.self_type)


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