type at rubycentral?

S

Schüle Daniel

Hello


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 ### <<< error?
Proc.new {|a,b|}.arity » 2
Proc.new {|a,b,c|}.arity » 3
Proc.new {|*a|}.arity » -1
Proc.new {|a,*b|}.arity » -2


I would say it's a typo

Regards, Daniel
 
S

Schüle Daniel

and one case is missing there

irb(main):169:0> proc{}.arity
=> -1

which means, all paramers are ignored(right?)
 
J

James Britt

Sch=FCle Daniel said:
I forgot to copy&paste the link
=20
http://www.rubycentral.com/book/ref_c_proc.html#Proc.arity
=20
=20
=20


I believe that page refers to Ruby 1.6.

See the docs for 1.8.4:

http://www.ruby-doc.org/core/classes/Proc.html#M000808



--=20
James Britt

http://web2.0validator.com - We're the Dot in Web 2.0
http://refreshingcities.org - Design, technology, usability
http://yourelevatorpitch.com - Finding Business Focus
http://www.jamesbritt.com - Playing with Better Toys
 
L

Logan Capaldo

and one case is missing there

irb(main):169:0> proc{}.arity
=3D> -1

which means, all paramers are ignored(right?)

Negative arities indicate the _minimum_ number of args to a proc that =20=

takes a variable number of args

min args =3D abs(arity + 1) if arity < 0 otherwise arity


so a proc with no arg speciafication is the same as proc { |*args| }. =20=

(You just can't get at the argument list)

proc { |a, *b| } will have an arity of -2

abs(-2 + 1) =3D 1 so it must be passed at least one arg

proc { |a, b, c| } will have an arity of 3

proc { || } will have an artity of zero (contrasted with proc { } )
 

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

wrong documentation 0
Arity? 2
How to distinguish blocks of certain arity in 1.8 4
[DOCBUG] Proc#arity 6
Re-naming a block 2
ANN main-4.4.0 0
Help with passing test 3
Tasks 1

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top