Class: TRuby::TypeScope

Inherits:
Object
  • Object
show all
Defined in:
lib/t_ruby/type_checker.rb

Overview

Scope for tracking variable types in a block

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent = nil) ⇒ TypeScope



97
98
99
100
# File 'lib/t_ruby/type_checker.rb', line 97

def initialize(parent = nil)
  @parent = parent
  @variables = {}
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



95
96
97
# File 'lib/t_ruby/type_checker.rb', line 95

def parent
  @parent
end

#variablesObject (readonly)

Returns the value of attribute variables.



95
96
97
# File 'lib/t_ruby/type_checker.rb', line 95

def variables
  @variables
end

Instance Method Details

#child_scopeObject



110
111
112
# File 'lib/t_ruby/type_checker.rb', line 110

def child_scope
  TypeScope.new(self)
end

#define(name, type) ⇒ Object



102
103
104
# File 'lib/t_ruby/type_checker.rb', line 102

def define(name, type)
  @variables[name] = type
end

#lookup(name) ⇒ Object



106
107
108
# File 'lib/t_ruby/type_checker.rb', line 106

def lookup(name)
  @variables[name] || @parent&.lookup(name)
end