Class: Liquid2::StaticAnalysis::StaticScope

Inherits:
Object
  • Object
show all
Defined in:
lib/liquid2/static_analysis.rb

Overview

Helper to manage variable scope during static analysis.

Instance Method Summary collapse

Constructor Details

#initialize(globals) ⇒ StaticScope

Returns a new instance of StaticScope.



99
100
101
# File 'lib/liquid2/static_analysis.rb', line 99

def initialize(globals)
  @stack = [globals]
end

Instance Method Details

#add(name) ⇒ Object



116
117
118
# File 'lib/liquid2/static_analysis.rb', line 116

def add(name)
  @stack.first.add(name)
end

#include?(key) ⇒ Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/liquid2/static_analysis.rb', line 103

def include?(key)
  @stack.any? { |scope| scope.include?(key) }
end

#popObject



112
113
114
# File 'lib/liquid2/static_analysis.rb', line 112

def pop
  @stack.pop
end

#push(scope) ⇒ Object



107
108
109
110
# File 'lib/liquid2/static_analysis.rb', line 107

def push(scope)
  @stack << scope
  self
end