Class: CapriccIo::CObject
- Inherits:
-
Object
- Object
- CapriccIo::CObject
- Defined in:
- lib/capriccio/runtime/object.rb
Instance Attribute Summary collapse
-
#proto ⇒ Object
Returns the value of attribute proto.
-
#slots ⇒ Object
Returns the value of attribute slots.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, value) ⇒ Object
- #call(*_args) ⇒ Object
- #clone(ruby_value = nil) ⇒ Object
- #def(name, &block) ⇒ Object
-
#initialize(proto = nil, value = nil) ⇒ CObject
constructor
A new instance of CObject.
- #to_s(level = 0) ⇒ Object (also: #inspect)
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
#proto ⇒ Object
Returns the value of attribute proto.
5 6 7 |
# File 'lib/capriccio/runtime/object.rb', line 5 def proto @proto end |
#slots ⇒ Object
Returns the value of attribute slots.
5 6 7 |
# File 'lib/capriccio/runtime/object.rb', line 5 def slots @slots end |
#value ⇒ Object
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
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 |