Class: TRuby::TypeScope
- Inherits:
-
Object
- Object
- TRuby::TypeScope
- Defined in:
- lib/t_ruby/type_checker.rb
Overview
Scope for tracking variable types in a block
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#variables ⇒ Object
readonly
Returns the value of attribute variables.
Instance Method Summary collapse
- #child_scope ⇒ Object
- #define(name, type) ⇒ Object
-
#initialize(parent = nil) ⇒ TypeScope
constructor
A new instance of TypeScope.
- #lookup(name) ⇒ Object
Constructor Details
#initialize(parent = nil) ⇒ TypeScope
Returns a new instance of 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
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
95 96 97 |
# File 'lib/t_ruby/type_checker.rb', line 95 def parent @parent end |
#variables ⇒ Object (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_scope ⇒ Object
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 |