Class: TreeStand::Visitors::TreeWalker

Inherits:
TreeStand::Visitor show all
Extended by:
T::Sig
Defined in:
lib/tree_stand/visitors/tree_walker.rb

Overview

Walks the tree depth-first and yields each node to the provided block.

Examples:

Create a list of all the nodes in the tree.

list = []
TreeStand::Visitors::TreeWalker.new(root) do |node|
  list << node
end.visit

See Also:

Instance Method Summary collapse

Methods inherited from TreeStand::Visitor

#around, #visit

Constructor Details

#initialize(node, &block) ⇒ void

Parameters:



28
29
30
31
# File 'lib/tree_stand/visitors/tree_walker.rb', line 28

def initialize(node, &block)
  super(node)
  @block = block
end

Instance Method Details

#on(node) ⇒ void

This method returns an undefined value.

Parameters:



34
# File 'lib/tree_stand/visitors/tree_walker.rb', line 34

def on(node) = @block.call(node)