J
Jon A. Lambert
From the Programming Ruby - The Pragmatic Programmer's Guide:
--class Proc ---
arity prc.arity -> anInteger
Returns the number of arguments required by the block. If the block
takes no arguments, returns -1. If it takes one argument, returns -2.
Otherwise, returns a positive argument count unless the last argument
is prefixed with *, in which case the argument count is negated. The
number of required arguments is anInteger for positive values, and
( anInteger +1).abs otherwise.
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
--class Method --
arity meth.arity -> aFixnum
Returns an indication of the number of arguments accepted by a method.
Returns a nonnegative integer for methods that take a fixed number of
arguments. For Ruby methods that take a variable number of arguments,
returns -n-1, where n is the number of required arguments. For methods
written in C, returns -1 if the call takes a variable number of arguments.
--class Proc ---
arity prc.arity -> anInteger
Returns the number of arguments required by the block. If the block
takes no arguments, returns -1. If it takes one argument, returns -2.
Otherwise, returns a positive argument count unless the last argument
is prefixed with *, in which case the argument count is negated. The
number of required arguments is anInteger for positive values, and
( anInteger +1).abs otherwise.
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
--class Method --
arity meth.arity -> aFixnum
Returns an indication of the number of arguments accepted by a method.
Returns a nonnegative integer for methods that take a fixed number of
arguments. For Ruby methods that take a variable number of arguments,
returns -n-1, where n is the number of required arguments. For methods
written in C, returns -1 if the call takes a variable number of arguments.