Class: RuboCop::Cop::VariableForce::Scope::ASTScanner

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeASTScanner

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