Class: Atomy::EvalLocalState
- Inherits:
-
LocalState
- Object
- LocalState
- Atomy::EvalLocalState
- Defined in:
- lib/atomy/locals.rb
Instance Attribute Summary
Attributes inherited from LocalState
Instance Method Summary collapse
-
#initialize(variable_scope) ⇒ EvalLocalState
constructor
A new instance of EvalLocalState.
- #local_count ⇒ Object
- #local_names ⇒ Object
- #new_local(name) ⇒ Object
-
#search_local(name) ⇒ Object
Returns a cached reference to a variable or searches all surrounding scopes for a variable.
Constructor Details
#initialize(variable_scope) ⇒ EvalLocalState
Returns a new instance of EvalLocalState.
25 26 27 |
# File 'lib/atomy/locals.rb', line 25 def initialize(variable_scope) @variable_scope = variable_scope end |
Instance Method Details
#local_count ⇒ Object
49 50 51 |
# File 'lib/atomy/locals.rb', line 49 def local_count 0 end |
#local_names ⇒ Object
53 54 55 |
# File 'lib/atomy/locals.rb', line 53 def local_names [] end |
#new_local(name) ⇒ Object
44 45 46 47 |
# File 'lib/atomy/locals.rb', line 44 def new_local(name) variable = CodeTools::Compiler::EvalLocalVariable.new(name) variables[name] = variable end |
#search_local(name) ⇒ Object
Returns a cached reference to a variable or searches all surrounding scopes for a variable. If no variable is found, it returns nil and a nested scope will create the variable in itself.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/atomy/locals.rb', line 33 def search_local(name) if variable = variables[name] return variable.nested_reference end if variable = search_scopes(name) variables[name] = variable return variable.nested_reference end end |