Class: Halunke::Runtime::HNativeObject

Inherits:
Object
  • Object
show all
Defined in:
lib/halunke/runtime/hnative_object.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runtime_class, ruby_value, source_code_position:) ⇒ HNativeObject

Returns a new instance of HNativeObject.



10
11
12
13
14
# File 'lib/halunke/runtime/hnative_object.rb', line 10

def initialize(runtime_class, ruby_value, source_code_position:)
  @runtime_class = runtime_class
  @ruby_value = ruby_value
  @source_code_position = source_code_position
end

Instance Attribute Details

#ruby_valueObject (readonly)

Returns the value of attribute ruby_value.



7
8
9
# File 'lib/halunke/runtime/hnative_object.rb', line 7

def ruby_value
  @ruby_value
end

#runtime_classObject (readonly)

Returns the value of attribute runtime_class.



6
7
8
# File 'lib/halunke/runtime/hnative_object.rb', line 6

def runtime_class
  @runtime_class
end

#source_code_positionObject (readonly)

Returns the value of attribute source_code_position.



8
9
10
# File 'lib/halunke/runtime/hnative_object.rb', line 8

def source_code_position
  @source_code_position
end

Instance Method Details

#inspect(context) ⇒ Object



23
24
25
# File 'lib/halunke/runtime/hnative_object.rb', line 23

def inspect(context)
  receive_message(context, "inspect", []).ruby_value
end

#receive_message(context, message_name, message_value, source_code_position: NullSourceCodePosition.new) ⇒ Object



16
17
18
19
20
21
# File 'lib/halunke/runtime/hnative_object.rb', line 16

def receive_message(context, message_name, message_value, source_code_position: NullSourceCodePosition.new)
  m = @runtime_class.lookup(message_name)
  m.receive_message(context, "call", [HArray.create_instance([self].concat(message_value))])
rescue KeyError
  raise HUnknownMessage.new(self.inspect(context), message_name, @runtime_class.instance_methods.keys, source_code_position) if m.nil?
end