Class: Halunke::Runtime::HFunction
- Inherits:
-
Object
- Object
- Halunke::Runtime::HFunction
- Defined in:
- lib/halunke/runtime/hfunction.rb
Instance Method Summary collapse
-
#initialize(signature, fn) ⇒ HFunction
constructor
A new instance of HFunction.
- #inspect(_context) ⇒ Object
- #receive_message(parent_context, message_name, message_value, source_code_position: NullSourceCodePosition.new) ⇒ Object
Constructor Details
#initialize(signature, fn) ⇒ HFunction
Returns a new instance of HFunction.
6 7 8 9 |
# File 'lib/halunke/runtime/hfunction.rb', line 6 def initialize(signature, fn) @signature = signature @fn = fn end |
Instance Method Details
#inspect(_context) ⇒ Object
24 25 26 |
# File 'lib/halunke/runtime/hfunction.rb', line 24 def inspect(_context) "Function (#{@signature.length})" end |
#receive_message(parent_context, message_name, message_value, source_code_position: NullSourceCodePosition.new) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/halunke/runtime/hfunction.rb', line 11 def (parent_context, , , source_code_position: NullSourceCodePosition.new) raise HUnknownMessage.new(self.inspect(parent_context), , ["call"], source_code_position) unless == "call" context = parent_context.create_child args = [0].ruby_value @signature.zip(args).each do |name, value| context[name.to_s] = value end @fn.call(context) end |