class Unparser::AST::LocalVariableScopeEnumerator

Local variable scope enumerator

Public Class Methods

each(node, &block) click to toggle source

Enumerate each node with its local variable scope

@param [Parser::AST::Node] node

@return [self]

@api private

# File lib/unparser/ast/local_variable_scope.rb, line 106
def self.each(node, &block)
  new.each(node, &block)
  self
end
new() click to toggle source

Initialize object

@return [undefined]

@api private

# File lib/unparser/ast/local_variable_scope.rb, line 94
def initialize
  @stack = [Set.new]
end

Public Instance Methods

each(node, &block) click to toggle source

Enumerate local variable scope scope

@return [self]

if block given

@return [Enumerator<Array<Symbol>>>]

otherwise

@api private

# File lib/unparser/ast/local_variable_scope.rb, line 121
def each(node, &block)
  visit(node, &block)
end

Private Instance Methods

current() click to toggle source
# File lib/unparser/ast/local_variable_scope.rb, line 127
def current
  @stack.last
end
define(name) click to toggle source
# File lib/unparser/ast/local_variable_scope.rb, line 156
def define(name)
  current << name
end
enter(node) click to toggle source
# File lib/unparser/ast/local_variable_scope.rb, line 141
def enter(node)
  case node.type
  when *RESET_NODES
    push_reset
  when ASSIGN_NODES
    define(node.children.first)
  when *INHERIT_NODES
    push_inherit
  end
end
leave(node) click to toggle source
# File lib/unparser/ast/local_variable_scope.rb, line 152
def leave(node)
  pop if CLOSE_NODES.include?(node.type)
end
pop() click to toggle source
# File lib/unparser/ast/local_variable_scope.rb, line 168
def pop
  @stack.pop
end
push_inherit() click to toggle source
# File lib/unparser/ast/local_variable_scope.rb, line 164
def push_inherit
  @stack << current.dup
end
push_reset() click to toggle source
# File lib/unparser/ast/local_variable_scope.rb, line 160
def push_reset
  @stack << Set.new
end
visit(node) { |node, dup, before| ... } click to toggle source
# File lib/unparser/ast/local_variable_scope.rb, line 131
def visit(node, &block)
  before = current.dup
  enter(node)
  yield node, current.dup, before
  node.children.each do |child|
    visit(child, &block) if child.is_a?(Parser::AST::Node)
  end
  leave(node)
end