# Type at rubycentral?

**URL:** <https://www.ruby-forum.com/t/type-at-rubycentral/78494>\
**Category:** Ruby\
**Created:** [March 8, 2006, 4:04pm UTC](https://www.ruby-forum.com/t/type-at-rubycentral/78494 "2006-03-08T16:04:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SchSSS\_le\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a183cd/32.png) [@SchSSS\_le\_Daniel](https://www.ruby-forum.com/u/SchSSS_le_Daniel)\
**Post date:** [March 8, 2006, 4:04pm UTC](https://www.ruby-forum.com/t/type-at-rubycentral/78494/1 "2006-03-08T16:04:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![SchSSS\_le\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a183cd/32.png) [@SchSSS\_le\_Daniel](https://www.ruby-forum.com/u/SchSSS_le_Daniel)\
**Post date:** [March 8, 2006, 4:11pm UTC](https://www.ruby-forum.com/t/type-at-rubycentral/78494/2 "2006-03-08T16:11:01Z")

</div>

and one case is missing there

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

which means, all paramers are ignored(right?)

---

<div class="post-metadata">

**Author:** ![SchSSS\_le\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a183cd/32.png) [@SchSSS\_le\_Daniel](https://www.ruby-forum.com/u/SchSSS_le_Daniel)\
**Post date:** [March 8, 2006, 6:31pm UTC](https://www.ruby-forum.com/t/type-at-rubycentral/78494/3 "2006-03-08T18:31:32Z")

</div>

I forgot to copy&paste the link

[http://www.rubycentral.com/book/ref\_c\_proc.html#Proc.arity](http://www.rubycentral.com/book/ref_c_proc.html#Proc.arity)

---

<div class="post-metadata">

**Author:** ![SchSSS\_le\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a183cd/32.png) [@SchSSS\_le\_Daniel](https://www.ruby-forum.com/u/SchSSS_le_Daniel)\
**Post date:** [March 8, 2006, 7:30pm UTC](https://www.ruby-forum.com/t/type-at-rubycentral/78494/4 "2006-03-08T19:30:32Z")

</div>

On Mar 8, 2006, at 10:08 AM, Schüle Daniel wrote:

> and one case is missing there
> 
> irb(main):169:0\> proc{}.arity  
> =\> -1
> 
> which means, all paramers are ignored(right?)

Negative arities indicate the _minimum_ number of args to a proc that  
takes a variable number of args

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

so a proc with no arg speciafication is the same as proc { |\*args| }.  
(You just can’t get at the argument list)

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

abs(-2 + 1) = 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 { } )

---

<div class="post-metadata">

**Author:** ![SchSSS\_le\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a183cd/32.png) [@SchSSS\_le\_Daniel](https://www.ruby-forum.com/u/SchSSS_le_Daniel)\
**Post date:** [March 8, 2006, 7:15pm UTC](https://www.ruby-forum.com/t/type-at-rubycentral/78494/5 "2006-03-08T19:15:08Z")

</div>

Schüle Daniel wrote:

> I forgot to copy&paste the link
> 
> [http://www.rubycentral.com/book/ref\_c\_proc.html#Proc.arity](http://www.rubycentral.com/book/ref_c_proc.html#Proc.arity)

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](http://www.ruby-doc.org/core/classes/Proc.html#M000808)

–  
James B.

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