I was fooling around with some examples using blocks this morning before work, and I noticed that the ruby docs for Proc#arity say:
Proc.new {}.arity #=> 0
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
But the ruby interpreter I’m using (MRI 1.8.6) actually returns these results:
Proc.new {}.arity #=> -1
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
Anyone know why the empty block returns -1 for its arity? Is it a known bug, or is it supposed to work like that and the documentation is wrong? In this case I think the documentation makes a lot more sense.
*** This appears to have been fixed in MRI 1.9 ***
0 comments ↓
There are no comments yet...Kick things off by filling out the form below.
Leave a Comment