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.
100 101 102 103 |
# File 'lib/t_ruby/type_checker.rb', line 100 def initialize(parent = nil) @parent = parent @variables = {} end |
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
98 99 100 |
# File 'lib/t_ruby/type_checker.rb', line 98 def parent @parent end |
#variables ⇒ Object (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_scope ⇒ Object
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 |