wrong documentation

D

Daniel Whitter

Hello,

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
474,201
Messages
2,571,052
Members
47,656
Latest member
rickwatson

Latest Threads

Top