Class: MimeActor::Dispatcher::MethodCall

Inherits:
Object
  • Object
show all
Defined in:
lib/mime_actor/dispatcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method_name, *args) ⇒ MethodCall

Returns a new instance of MethodCall.



12
13
14
15
16
# File 'lib/mime_actor/dispatcher.rb', line 12

def initialize(method_name, *args)
  @method_name = method_name
  @args = args
  validate!
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



10
11
12
# File 'lib/mime_actor/dispatcher.rb', line 10

def args
  @args
end

#method_nameObject (readonly)

Returns the value of attribute method_name.



10
11
12
# File 'lib/mime_actor/dispatcher.rb', line 10

def method_name
  @method_name
end

Instance Method Details

#call(target) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/mime_actor/dispatcher.rb', line 18

def call(target)
  raise MimeActor::ActorNotFound, method_name unless target.respond_to?(method_name, true)

  method_call = target.method(method_name)
  filtered_args = method_call.arity.negative? ? args : args.take(method_call.arity)
  method_call.call(*filtered_args)
end