I would like to get the arity of a method. However, arity is a method
of Method, and I can only get a Method from the method method of Object
(phew!).
So it appears impossible to get the arity of a method in a class
without making an instance of that class. Is this true?
A hypothetical use would be to print out all classes with their arity
at a given time during execution (and making dummy instances could
cause unwanted side-effects).
–
([ Kent Dahl ]/)_ ~[ Kent Dahl - Kent Dahl ]/~
))_student_/(( _d L b_/ (pre-) Master of Science in Technology )
( __õ|õ// ) )Industrial economics and technological management(
_/ö____/ (_engineering.discipline=Computer::Technology)
I would like to get the arity of a method. However, arity is a method
of Method, and I can only get a Method from the method method of Object
(phew!).
So it appears impossible to get the arity of a method in a class
without making an instance of that class. Is this true?
A hypothetical use would be to print out all classes with their arity
at a given time during execution (and making dummy instances could
cause unwanted side-effects).
Here’s a starting point. Note that, of course, you get a lot more methods than you bargained for, because it will show you all the inherited methods, too.
Hope it helps.
···
def dump_methods(klass)
klass.methods.each do |name|
method = Fred.method(name)