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

Returns a new instance of TypeScope.



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

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

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



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

def parent
  @parent
end

#variablesObject (readonly)

Returns the value of attribute variables.



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

def variables
  @variables
end

Instance Method Details

#child_scopeObject



113
114
115
# File 'lib/t_ruby/type_checker.rb', line 113

def child_scope
  TypeScope.new(self)
end

#define(name, type) ⇒ Object



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

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

#lookup(name) ⇒ Object



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

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