Class: Unparser::AST::Walker

Inherits:
Object
  • Object
show all
Defined in:
lib/unparser/ast.rb

Overview

Controlled AST walker walking the AST in deeth first search with pre order

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(node, controller = TAUTOLOGY, &block) ⇒ self

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Call ast walker

Parameters:

  • node (Parser::AST::Node)

Returns:

  • (self)


179
180
181
182
# File 'lib/unparser/ast.rb', line 179

def self.call(node, controller = TAUTOLOGY, &block)
  new(block, controller).call(node)
  self
end

Instance Method Details

#call(node) ⇒ self

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Call walker with node

Parameters:

  • node (Parser::AST::Node)

Returns:

  • (self)


192
193
194
195
196
197
198
199
200
# File 'lib/unparser/ast.rb', line 192

def call(node)
  return unless controller.call(node)
  block.call(node)
  node.children.each do |child|
    next unless child.kind_of?(Parser::AST::Node)
    call(child)
  end
  self
end