Class: ASTTransform::AbstractAnalysis

Inherits:
AbstractProcessor show all
Defined in:
lib/ast_transform/abstract_analysis.rb

Overview

Base class for read-only analysis passes: subclass, harvest state in on_* handlers (always call super so traversal continues), and expose results through readers. The walk still functionally rebuilds the tree — Parser::AST::Processor has no read-only mode — but run discards the rebuilt tree, so handlers never need to care what they return.

class SendCounter < ASTTransform::AbstractAnalysis
attr_reader :count

def initialize
  @count = 0
  super
end

def on_send(node)
  @count += 1
  super
end
end

SendCounter.new.run(SourceParser.new.parse(source)).count

Instance Method Summary collapse

Methods inherited from AbstractProcessor

#on_ast_thunk, #process

Methods included from TransformationHelper

included

Instance Method Details

#run(node) ⇒ ASTTransform::AbstractAnalysis

Runs this analysis on node, discarding the rebuilt tree. Note: If you want to add one-time setup or result finalization, override this, then call super.

Parameters:

  • node (Parser::AST::Node)

    The node to be analyzed.

Returns:



33
34
35
36
# File 'lib/ast_transform/abstract_analysis.rb', line 33

def run(node)
  process(node)
  self
end