Hi,
In AspectR we would like to get the arity of methods of classes without
having instances of the classes. Is there some way to do it?
If we had an object we'd simply do
arity = object.method(method).arity
but if you don't know how to get an instance...
BTW, what we're trying to acheive is to get a string of arguments
corresponding to the original args/arity of a method as in:
def generate_args(obj, method)
arity = obj.method(method).arity
if arity < 0
args = (0...(-1-arity)).to_a.collect{|i| "a#{i}"}.join(",")
args += "," if arity < -1
args + "*args,&block"
else
(0...arity).to_a.collect{|i| "a#{i}"}.join(",")
end
end
This is generally (?) a good idea when working with code that
redefines/modifies existing methods since it'll not change the arity
ie. be more transparent. The "standard way" of simply using
"*args,&block" may brake code that relies/exploits arity of methods... Or
is there a flaw in this reasoning? Alternative ways?
Regards,
Robert