Class: Twostroke::Runtime::ObjectScope

Inherits:
Object
  • Object
show all
Defined in:
lib/twostroke/runtime/scope.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#objectObject (readonly)

Returns the value of attribute object.



48
49
50
# File 'lib/twostroke/runtime/scope.rb', line 48

def object
  @object
end

#parentObject (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

#closeObject



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_scopeObject



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