Class: Twostroke::Runtime::ObjectScope
- Inherits:
-
Object
- Object
- Twostroke::Runtime::ObjectScope
- Defined in:
- lib/twostroke/runtime/scope.rb
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
- #close ⇒ Object
- #declare(var) ⇒ Object
- #delete(var) ⇒ Object
- #get_var(var) ⇒ Object
- #global_scope ⇒ Object
- #has_var(var) ⇒ Object
-
#initialize(object, parent) ⇒ ObjectScope
constructor
A new instance of ObjectScope.
- #set_var(var, value) ⇒ Object
Constructor Details
#initialize(object, parent) ⇒ ObjectScope
Returns a new instance of ObjectScope.
50 51 52 |
# File 'lib/twostroke/runtime/scope.rb', line 50 def initialize(object, parent) @parent, @object = parent, object end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
48 49 50 |
# File 'lib/twostroke/runtime/scope.rb', line 48 def object @object end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
48 49 50 |
# File 'lib/twostroke/runtime/scope.rb', line 48 def parent @parent end |
Instance Method Details
#close ⇒ Object
86 87 88 |
# File 'lib/twostroke/runtime/scope.rb', line 86 def close Scope.new self end |
#declare(var) ⇒ Object
74 75 76 |
# File 'lib/twostroke/runtime/scope.rb', line 74 def declare(var) parent.declare var end |
#delete(var) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/twostroke/runtime/scope.rb', line 78 def delete(var) if has_var var object.delete var.to_s else parent.delete var end end |
#get_var(var) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/twostroke/runtime/scope.rb', line 54 def get_var(var) if object.has_property var.to_s object.get var.to_s else parent.get_var var end end |
#global_scope ⇒ Object
90 91 92 |
# File 'lib/twostroke/runtime/scope.rb', line 90 def global_scope @global_scope ||= parent.global_scope end |
#has_var(var) ⇒ Object
70 71 72 |
# File 'lib/twostroke/runtime/scope.rb', line 70 def has_var(var) object.has_property(var.to_s) || parent.has_var(var) end |
#set_var(var, value) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/twostroke/runtime/scope.rb', line 62 def set_var(var, value) if object.has_property var.to_s object.put var.to_s, value else parent.set_var var, value end end |