Class: ToyLangObject

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

Direct Known Subclasses

ToyLangClass

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runtime_class, ruby_value = self) ⇒ ToyLangObject

Returns a new instance of ToyLangObject.



6
7
8
9
# File 'lib/toylang/runtime/object.rb', line 6

def initialize(runtime_class, ruby_value = self)
  @runtime_class = runtime_class
  @ruby_value = ruby_value
end

Instance Attribute Details

#ruby_valueObject

Returns the value of attribute ruby_value.



4
5
6
# File 'lib/toylang/runtime/object.rb', line 4

def ruby_value
  @ruby_value
end

#runtime_classObject

Returns the value of attribute runtime_class.



4
5
6
# File 'lib/toylang/runtime/object.rb', line 4

def runtime_class
  @runtime_class
end

Instance Method Details

#call(method, arguments = []) ⇒ Object



11
12
13
# File 'lib/toylang/runtime/object.rb', line 11

def call(method, arguments = [])
  @runtime_class.lookup(method).call(self, arguments)
end

#inspectObject



15
16
17
# File 'lib/toylang/runtime/object.rb', line 15

def inspect
  "#<ToyLangObject class=#{@runtime_class} ruby_value=#{@ruby_value}"
end