From: Paul Brannan Date: 2001-12-14T01:53:39+09:00 Subject: [ruby-talk:28422] why is Proc's arity function so weird? From the Pickaxe book (online, since the printed version is wrong, as is the online description of Proc#arity): Proc.new {||}.arity � 0 Proc.new {|a|}.arity � -1 Proc.new {|a,b|}.arity � 2 Proc.new {|a,b,c|}.arity � 3 Proc.new {|*a|}.arity � -1 Proc.new {|a,*b|}.arity � -2 Why does arity return -1 when there is 1 argument? The problem with this is the following: irb(main):003:0> p = Proc.new {|a|} # irb(main):004:0> p.call(1, 2, 3) nil irb(main):005:0> p = Proc.new {|a, b|} # irb(main):006:0> p.call(1, 2, 3) ArgumentError: wrong # of arguments (3 for 2) from (irb):6 from (irb):5:in `call' from (irb):6 If my Proc takes one argument, then I can pass as many arguments to it as I want, but if it takes two arguments, then I get an ArgumentError if I try to do that. I understand that the reasoning here is to allow: h = { 1=>2, 2=>3 } h.each do |pair| p pair end which produces: [1, 2] [2, 3] but there really is no advantage to writing it that way versus: h = { 1=>2, 2=>3 } h.each do |*pair| p pair end Is there another reason for this behavior that I am missing? Paul