Here are some other examples:

  def m1(x);end
  l1 = lambda{|x|}
  p1 = proc{|x|}

  method(:m1).arity # => 1
  l1.arity          # => 1
  p1.arity          # => 1

When there are no optional parameters (and zero or more required 
parameters), all three objects report the same arity.  This is what 
you'd expect in a normal situation.


  def m2(x,y=1);end
  l2 = lambda{|x,y=1|}
  p2 = proc{|x,y=1|}

  method(:m2).arity # => -2
  l2.arity          # => -2
  p2.arity          # => 1

With an optional/default parameter, the Proc object reports number of 
"required" parameters*, while the Method and Lambda objects report the 
one's complement.


  def m3(x=1,y=1,z=1);end
  l3 = lambda{|x=1,y=1,z=1|}
  p3 = proc{|x=1,y=1,z=1|}

  method(:m3).arity # => -1
  l3.arity          # => -1
  p3.arity          # => 0

Just to demonstrate that -N doesn't mean "up to N parameters".

I suppose the logic is:

1. if arity is positive, there are that many required parameters
2. if arity is negative,
  a. required parameters = ~arity
  b. there is some (unknown, natural) number of optional parameters

The real question is: why does Proc _not_ report the one's complement?

* note: calling them "required" parameters for a proc is a bit 
misleading: proc{|x|x}[] #=> nil

-- 
Posted via http://www.ruby-forum.com/.