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
- #get_var(var) ⇒ Object
- #global_scope ⇒ Object
- #has_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.
46 47 48 |
# File 'lib/twostroke/runtime/scope.rb', line 46 def initialize(object, parent) @parent, @object = parent, object end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
44 45 46 |
# File 'lib/twostroke/runtime/scope.rb', line 44 def object @object end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
44 45 46 |
# File 'lib/twostroke/runtime/scope.rb', line 44 def parent @parent end |
Instance Method Details
#close ⇒ Object
74 75 76 |
# File 'lib/twostroke/runtime/scope.rb', line 74 def close Scope.new self end |
#declare(var) ⇒ Object
70 71 72 |
# File 'lib/twostroke/runtime/scope.rb', line 70 def declare(var) parent.declare var end |
#get_var(var) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/twostroke/runtime/scope.rb', line 50 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
78 79 80 |
# File 'lib/twostroke/runtime/scope.rb', line 78 def global_scope @global_scope ||= parent.global_scope end |
#has_var ⇒ Object
66 67 68 |
# File 'lib/twostroke/runtime/scope.rb', line 66 def has_var object.has_property(var.to_s) || parent.has_var(var) end |
#set_var(var, value) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/twostroke/runtime/scope.rb', line 58 def set_var(var, value) if object.has_property var.to_s object.put var.to_s, value else parent.set_var var.to_s, value end end |