From: Brian Candler Date: 2003-07-09T19:36:41+09:00 Subject: Idea: arity as a range This may have been suggested before, but I wondered if the use of negative numbers for arity could be simplified using ranges: def x(a,b,c); end; method(:x).arity #=> 3 def x(a,b,c=nil); end; method(:x).arity #=> (2..3) def x(a,b,*c); end; method(:x).arity #=> (2..nil) The last example shows a range without an upper bound, which would also be new. To avoid that, 'arity' could return an object instead: class Arity def initialize(min=0,max=min) @min = min @max = max end # backwards compat? def to_i if @min == @max @min else -@min-1 end end def coerce(y) return [to_i, y] if y.kind_of?(Numeric) raise TypeError end # methods based on Range def min @min end def max @max end def ===(val) val >= @min && (@max.nil? || val <= @max) end end Just a thought... Regards, Brian.