Class: RuboCop::Cop::VariableForce::Scope::ASTScanner
- Inherits:
-
Object
- Object
- RuboCop::Cop::VariableForce::Scope::ASTScanner
- Defined in:
- lib/rubocop/cop/variable_force/scope.rb
Overview
This class provides a ways to scan AST with tracking ancestor nodes.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ ASTScanner
constructor
A new instance of ASTScanner.
- #scan(node, &block) ⇒ Object
Constructor Details
#initialize ⇒ ASTScanner
Returns a new instance of ASTScanner.
60 61 62 |
# File 'lib/rubocop/cop/variable_force/scope.rb', line 60 def initialize @ancestor_nodes = [] end |
Class Method Details
.scan(node, &block) ⇒ Object
56 57 58 |
# File 'lib/rubocop/cop/variable_force/scope.rb', line 56 def self.scan(node, &block) new.scan(node, &block) end |
Instance Method Details
#scan(node, &block) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/rubocop/cop/variable_force/scope.rb', line 64 def scan(node, &block) @ancestor_nodes.push(node) node.children.each do |child| next unless child.is_a?(Parser::AST::Node) yield child, @ancestor_nodes scan(child, &block) end @ancestor_nodes.pop end |