Class: CapriccIo::Method

Inherits:
CObject show all
Defined in:
lib/capriccio/runtime/method.rb

Instance Attribute Summary

Attributes inherited from CObject

#proto, #slots, #value

Instance Method Summary collapse

Methods inherited from CObject

#[], #[]=, #clone, #def, #to_s

Constructor Details

#initialize(context, message) ⇒ Method

Returns a new instance of Method.



5
6
7
8
9
# File 'lib/capriccio/runtime/method.rb', line 5

def initialize(context, message)
  @definition_context = context
  @message = message
  super(Runtime['Method'])
end

Instance Method Details

#call(receiver, calling_context, *args) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/capriccio/runtime/method.rb', line 11

def call(receiver, calling_context, *args)
  method_context              = @definition_context.clone
  method_context['self']      = receiver
  method_context['arguments'] = Runtime['List'].clone(args)

  method_context['eval_arg'] = proc do |_receiver, context, at|
    (args[at.call(context).value] || Runtime['nil']).call(calling_context)
  end
  @message.call(method_context)
end