From: Harry Ohlsen Date: 2003-08-28T17:37:08+09:00 Subject: Re: getting the arity Jeff Mitchell wrote: > Hi, > > 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) puts "#{name} arity #{method.arity}" end end class Fred def f(a, b, c) end def g(x) end end dump_methods Fred