Class: JRuby::Lint::AST::Visitor
- Inherits:
-
Object
- Object
- JRuby::Lint::AST::Visitor
- Includes:
- Enumerable
- Defined in:
- lib/jruby/lint/ast.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#ast ⇒ Object
readonly
Returns the value of attribute ast.
Instance Method Summary collapse
- #each(&block) ⇒ Object (also: #each_node, #traverse)
-
#initialize(ast) ⇒ Visitor
constructor
A new instance of Visitor.
- #method_missing(name, *args, &block) ⇒ Object
- #visit(method, node) ⇒ Object
Constructor Details
#initialize(ast) ⇒ Visitor
Returns a new instance of Visitor.
37 38 39 |
# File 'lib/jruby/lint/ast.rb', line 37 def initialize(ast) @ast = ast end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/jruby/lint/ast.rb', line 58 def method_missing(name, *args, &block) if name.to_s =~ /^visit/ visit(name, *args) else super end end |
Instance Attribute Details
#ast ⇒ Object (readonly)
Returns the value of attribute ast.
35 36 37 |
# File 'lib/jruby/lint/ast.rb', line 35 def ast @ast end |
Instance Method Details
#each(&block) ⇒ Object Also known as: each_node, traverse
41 42 43 44 45 46 |
# File 'lib/jruby/lint/ast.rb', line 41 def each(&block) @block = block ast.accept(self) ensure @block = nil end |
#visit(method, node) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/jruby/lint/ast.rb', line 51 def visit(method, node) @block.call(node) if @block node.child_nodes.each do |cn| cn.accept(self) rescue nil end end |