Class: Celluloid::Call

Inherits:
Object
  • Object
show all
Defined in:
lib/celluloid/calls.rb

Overview

Calls represent requests to an actor

Direct Known Subclasses

AsyncCall, SyncCall

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(caller, method, arguments = [], block = nil) ⇒ Call

Returns a new instance of Call.



6
7
8
# File 'lib/celluloid/calls.rb', line 6

def initialize(caller, method, arguments = [], block = nil)
  @caller, @method, @arguments, @block = caller, method, arguments, block
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



4
5
6
# File 'lib/celluloid/calls.rb', line 4

def arguments
  @arguments
end

#blockObject (readonly)

Returns the value of attribute block.



4
5
6
# File 'lib/celluloid/calls.rb', line 4

def block
  @block
end

#callerObject (readonly)

Returns the value of attribute caller.



4
5
6
# File 'lib/celluloid/calls.rb', line 4

def caller
  @caller
end

#methodObject (readonly)

Returns the value of attribute method.



4
5
6
# File 'lib/celluloid/calls.rb', line 4

def method
  @method
end

Instance Method Details

#check_signature(obj) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/celluloid/calls.rb', line 10

def check_signature(obj)
  unless obj.respond_to? @method
    raise NoMethodError, "undefined method `#{@method}' for #{obj.inspect}"
  end

  begin
    arity = obj.method(@method).arity
  rescue NameError
    # If the object claims it responds to a method, but it doesn't exist,
    # then we have to assume method_missing will do what it says
    @arguments.unshift(@method)
    @method = :method_missing
    return
  end

  if arity >= 0
    if arguments.size != arity
      raise ArgumentError, "wrong number of arguments (#{arguments.size} for #{arity})"
    end
  elsif arity < -1
    mandatory_args = -arity - 1
    if arguments.size < mandatory_args
      raise ArgumentError, "wrong number of arguments (#{arguments.size} for #{mandatory_args})"
    end
  end
end