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.



46
47
48
# File 'lib/twostroke/runtime/scope.rb', line 46

def initialize(object, parent)
  @parent, @object = parent, object
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



44
45
46
# File 'lib/twostroke/runtime/scope.rb', line 44

def object
  @object
end

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

#closeObject



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_scopeObject



78
79
80
# File 'lib/twostroke/runtime/scope.rb', line 78

def global_scope
  @global_scope ||= parent.global_scope
end

#has_varObject



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