From: Philip Mak Date: 2002-10-17T15:51:03+09:00 Subject: Re: How to tell if a method accepts this many arguments? On Wed, Oct 16, 2002 at 09:27:09PM -0400, Philip Mak wrote: > there is a Method#arity method, but if the method takes a variable > number of arguments, Method#arity only tells me the minimum number > of arguments, not the maximum number. Thinking more about this, wouldn't it make more sense for Method#arity to return a Range? e.g.: def x(a, b) # arity is 2..2 def x(a, b, c = nil) # arity is 2..3 def x(a, b, *arr) # arity is 2..Infinity (yes, Ruby supports # infinite ranges) Then I could use the Range#=== operator to determine whether that's too many arguments. e.g.: if the_method.arity === args.length the_method.call *args else puts "Invalid number of arguments to command." end