Class: ASTTransform::AbstractAnalysis
- Inherits:
-
AbstractProcessor
- Object
- Parser::AST::Processor
- AbstractProcessor
- ASTTransform::AbstractAnalysis
- 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
-
#run(node) ⇒ ASTTransform::AbstractAnalysis
Runs this analysis on
node, discarding the rebuilt tree.
Methods inherited from AbstractProcessor
Methods included from TransformationHelper
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.
33 34 35 36 |
# File 'lib/ast_transform/abstract_analysis.rb', line 33 def run(node) process(node) self end |