D
Daniel Whitter
Hello,
to ``proc.arity´´ it is documented:
Fact is if you have only arguments without '*' the count of the
arguments is returned.
If you use a '*' for the last argument the return value of 'arity' is
negated.
Means the examples give:
0
1
2
3
-1
-2
greetings,
Daniel
to ``proc.arity´´ it is documented:
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
Fact is if you have only arguments without '*' the count of the
arguments is returned.
If you use a '*' for the last argument the return value of 'arity' is
negated.
Means the examples give:
0
1
2
3
-1
-2
greetings,
Daniel