When I delegate methods on instances of class A
to $delegation_target
as below:
$delegation_target = ""
class A
def method_missing *args, ≺ $delegation_target.send(*args, &pr) end
def respond_to_missing? *args; $delegation_target.respond_to?(*args) end
end
the arity
of the methods on instances of A
returns -1
irrespective of the arity
of the methods on $delegation_target
:
def $delegation_target.foo; end
A.new.method(:foo).arity # => -1
def $delegation_target.foo arg1; end
A.new.method(:foo).arity # => -1
def $delegation_target.foo arg1, arg2; end
A.new.method(:foo).arity # => -1
def $delegation_target.foo arg1, arg2, arg3; end
A.new.method(:foo).arity # => -1
Where does this -1
come from? And, is there a way to make it so that, for any possible method name m
, A.new.method(m).arity
returns the arity of $delegation_target.method(m)
(if it is defined)?