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.
54 55 56 |
# File 'lib/twostroke/runtime/scope.rb', line 54 def initialize(object, parent) @parent, @object = parent, object end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
52 53 54 |
# File 'lib/twostroke/runtime/scope.rb', line 52 def object @object end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
52 53 54 |
# File 'lib/twostroke/runtime/scope.rb', line 52 def parent @parent end |
Instance Method Details
#close ⇒ Object
90 91 92 |
# File 'lib/twostroke/runtime/scope.rb', line 90 def close Scope.new self end |
#declare(var) ⇒ Object
78 79 80 |
# File 'lib/twostroke/runtime/scope.rb', line 78 def declare(var) parent.declare var end |
#delete(var) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/twostroke/runtime/scope.rb', line 82 def delete(var) if has_var var object.delete var.to_s else parent.delete var end end |
#get_var(var) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/twostroke/runtime/scope.rb', line 58 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
94 95 96 |
# File 'lib/twostroke/runtime/scope.rb', line 94 def global_scope @global_scope ||= parent.global_scope end |
#has_var(var) ⇒ Object
74 75 76 |
# File 'lib/twostroke/runtime/scope.rb', line 74 def has_var(var) object.has_property(var.to_s) || parent.has_var(var) end |
#set_var(var, value) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/twostroke/runtime/scope.rb', line 66 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 |