# Code Review: arity

**URL:** <https://www.ruby-forum.com/t/code-review-arity/150131>\
**Category:** IronRuby\
**Created:** [October 4, 2008, 6:24am UTC](https://www.ruby-forum.com/t/code-review-arity/150131 "2008-10-04T06:24:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![grujildo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/94ad74/32.png) [@grujildo](https://www.ruby-forum.com/u/grujildo)\
**Post date:** [October 4, 2008, 6:24am UTC](https://www.ruby-forum.com/t/code-review-arity/150131/1 "2008-10-04T06:24:42Z")

</div>

tfpt review “/shelveset:arity;REDMOND\tomat”  
Comment :  
Fixes bugs in block parameters:

1. Anonymous unsplat parameters were not handled correctly (the  
parser ignored them):  
def y  
a = [1,2,3,4,5]  
yield a,[6]  
end

y { |(x,y,_),_| p x,y }  
2) Arity wasn’t calculated correctly. Arity depends upon AST  
structure that is not preserved in runtime. Therefore we need to  
calculate block arity at compile time and save it to BlockDispatcher.  
Some peculiar cases:

Proc.new{|(a,b,c,_)|}.arity.should == -4  
Proc.new{|(_)|}.arity.should == -1  
Proc.new{}.arity.should == -1  
Proc.new{||}.arity.should == 0  
Proc.new{x,}.arity.should == 1  
Proc.new{(x,)}.arity.should == 1

Tomas

---

<div class="post-metadata">

**Author:** ![grujildo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/94ad74/32.png) [@grujildo](https://www.ruby-forum.com/u/grujildo)\
**Post date:** [October 5, 2008, 7:20am UTC](https://www.ruby-forum.com/t/code-review-arity/150131/2 "2008-10-05T07:20:58Z")

</div>

Looks good. One minor formatting problem: Some of the changed parts of  
parser.y are now using tab characters instead of spaces.

In the BlockSignatureAttributes enumeration (in BlockDispatcher.cs),  
there’s a comment that “bits 31…3 store arity”. Are you numbering bits  
from 1? I’m used to numbering them from zero :).
