Module: Wool::SexpAnalysis::Visitor
Overview
Visitor: a set of methods for visiting an AST. The default implementations visit each child and do no other processing. By including this module, and implementing certain methods, you can do your own processing on, say, every instance of a :rescue AST node. The default implementation will go arbitrarily deep in the AST tree until it hits a method you define.
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &blk) ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/wool/analysis/visitor.rb', line 27
def method_missing(meth, *args, &blk)
if meth.to_s[0,6] == 'visit_'
default_visit args.first
else
raise
end
end
|
Instance Method Details
#default_visit(node) ⇒ Object
23
24
25
|
# File 'lib/wool/analysis/visitor.rb', line 23
def default_visit(node)
node.children.select {|x| Sexp === x}.each {|x| visit(x) }
end
|
#visit(node) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/wool/analysis/visitor.rb', line 11
def visit(node)
case node
when Sexp
case node[0]
when ::Symbol
send("visit_#{node[0]}", node)
when Array
node.each {|x| visit(x)}
end
end
end
|