Class: CapriccIo::CObject

Inherits:
Object
  • Object
show all
Defined in:
lib/capriccio/runtime/object.rb

Direct Known Subclasses

Message, Method

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(proto = nil, value = nil) ⇒ CObject

Returns a new instance of CObject.



7
8
9
10
11
# File 'lib/capriccio/runtime/object.rb', line 7

def initialize(proto = nil, value = nil)
  @proto = proto
  @value = value
  @slots = {}
end

Instance Attribute Details

#protoObject

Returns the value of attribute proto.



5
6
7
# File 'lib/capriccio/runtime/object.rb', line 5

def proto
  @proto
end

#slotsObject

Returns the value of attribute slots.



5
6
7
# File 'lib/capriccio/runtime/object.rb', line 5

def slots
  @slots
end

#valueObject

Returns the value of attribute value.



5
6
7
# File 'lib/capriccio/runtime/object.rb', line 5

def value
  @value
end

Instance Method Details

#[](name) ⇒ Object

Raises:



13
14
15
16
17
18
# File 'lib/capriccio/runtime/object.rb', line 13

def [](name)
  return @slots[name] if @slots.key?(name)
  return @proto[name] if @proto

  raise CapriccIo::Error, "Missing slot: #{name.inspect}"
end

#[]=(name, value) ⇒ Object



20
21
22
# File 'lib/capriccio/runtime/object.rb', line 20

def []=(name, value)
  @slots[name] = value
end

#call(*_args) ⇒ Object



28
29
30
# File 'lib/capriccio/runtime/object.rb', line 28

def call(*_args)
  self
end

#clone(ruby_value = nil) ⇒ Object



32
33
34
# File 'lib/capriccio/runtime/object.rb', line 32

def clone(ruby_value = nil)
  CObject.new(self, ruby_value)
end

#def(name, &block) ⇒ Object



24
25
26
# File 'lib/capriccio/runtime/object.rb', line 24

def def(name, &block)
  @slots[name] = block
end

#to_s(level = 0) ⇒ Object Also known as: inspect



36
37
38
39
40
41
42
43
# File 'lib/capriccio/runtime/object.rb', line 36

def to_s(level = 0)
  s = '  ' * level
  s << '<CObject'
  s << " @proto=#{@proto}" unless @proto.nil?
  s << ", @value=#{@value.inspect}" unless @proto.nil?
  s << ", @slots=#{@slots.keys}" unless @slots.empty?
  "#{s}>"
end