module Concurrent::Async

def self.validate_argc(obj, method, *args)

Other tags:
    See: http://www.ruby-doc.org/core-2.1.0/BasicObject.html#method-i-method_missing - BasicObject#method_missing
    See: http://ruby-doc.org/core-2.1.0/Object.html#method-i-respond_to-3F - Object#respond_to?
    See: http://www.ruby-doc.org/core-2.1.1/Method.html#method-i-arity - Method#arity

Other tags:
    Note: - This check is imperfect because of the way Ruby reports the arity of

Raises:
  • (ArgumentError) - the given `args` do not match the arity of `method`
  • (NameError) - the object does not respond to `method` method

Parameters:
  • args (Array) -- zero or more arguments for the arity check
  • method (Symbol) -- the method to check the object for
  • obj (Object) -- the object to check against
def self.validate_argc(obj, method, *args)
  argc = args.length
  arity = obj.method(method).arity
  if arity >= 0 && argc != arity
    raise ArgumentError.new("wrong number of arguments (#{argc} for #{arity})")
  elsif arity < 0 && (arity = (arity + 1).abs) > argc
    raise ArgumentError.new("wrong number of arguments (#{argc} for #{arity}..*)")
  end
end