Class: VariableScopeStack

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/yast/variable_scope.rb

Overview

A stack of VariableScope

Instance Method Summary collapse

Constructor Details

#initializeVariableScopeStack

Returns a new instance of VariableScopeStack.



51
52
53
54
# File 'lib/rubocop/yast/variable_scope.rb', line 51

def initialize
  outer_scope = VariableScope.new
  @stack = [outer_scope]
end

Instance Method Details

#innermostObject

The innermost, or current VariableScope



57
58
59
# File 'lib/rubocop/yast/variable_scope.rb', line 57

def innermost
  @stack.last
end

#with_copy(&block) ⇒ Object

Run block using a copy of the innermost scope

Returns:

  • the scope as the block left it, popped from the stack



72
73
74
75
76
# File 'lib/rubocop/yast/variable_scope.rb', line 72

def with_copy(&block)
  @stack.push innermost.dup
  block.call
  @stack.pop
end

#with_new(&block) ⇒ Object

Run block using a new clean scope

Returns:

  • the scope as the block left it, popped from the stack



63
64
65
66
67
68
# File 'lib/rubocop/yast/variable_scope.rb', line 63

def with_new(&block)
  @stack.push VariableScope.new
  RuboCop::Yast.logger.debug "SCOPES #{@stack.inspect}"
  block.call
  @stack.pop
end