# Proc argument names instead of arity

**URL:** <https://www.ruby-forum.com/t/proc-argument-names-instead-of-arity/143094>\
**Category:** Ruby\
**Created:** [July 15, 2008, 6:38am UTC](https://www.ruby-forum.com/t/proc-argument-names-instead-of-arity/143094 "2008-07-15T06:38:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![macario](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b4bc9f/32.png) [@macario](https://www.ruby-forum.com/u/macario)\
**Post date:** [July 15, 2008, 6:38am UTC](https://www.ruby-forum.com/t/proc-argument-names-instead-of-arity/143094/1 "2008-07-15T06:38:04Z")

</div>

Hi, i am trying to make a SuperCollider([http://www.audiosynth.com/](http://www.audiosynth.com/))  
client for ruby and I want it to be as close as using SCLang.

Both languages are very similar, although i find ruby more concise but  
SCLang function object (equivalent to ruby proc) can give you an array  
of the function’s argument names which is the basis of the synth  
creation process, so in SCLang you can do:

var func = { |arg1, arg2| arg1 + arg2 }  
=\> a Function  
var def = func.def  
=\> a FunctionDef - closed  
def.argumentNames  
=\> [arg1, arg2]

Is there any way of doing this with ruby?

---

<div class="post-metadata">

**Author:** ![macario](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b4bc9f/32.png) [@macario](https://www.ruby-forum.com/u/macario)\
**Post date:** [July 15, 2008, 7:25am UTC](https://www.ruby-forum.com/t/proc-argument-names-instead-of-arity/143094/2 "2008-07-15T07:25:52Z")

</div>

> var func = { |arg1, arg2| arg1 + arg2 }  
> =\> a Function  
> var def = func.def  
> =\> a FunctionDef - closed  
> def.argumentNames  
> =\> [arg1, arg2]
> 
> Is there any way of doing this with ruby?

Appears that there is.  
~ sudo gem install ParseTree

> > class A; def go(b); end; end  
> > args = ParseTree.translate(A, :go)[2][1][1]  
> > =\> [:args, :b]

Only works with MRI.  
Been using it recently for an auto named variable generator.  
GL.  
-R

---

<div class="post-metadata">

**Author:** ![macario](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b4bc9f/32.png) [@macario](https://www.ruby-forum.com/u/macario)\
**Post date:** [July 15, 2008, 8:07am UTC](https://www.ruby-forum.com/t/proc-argument-names-instead-of-arity/143094/3 "2008-07-15T08:07:56Z")

</div>

> I want to get the arg names for a block passed as an argument, I will  
> check the API. Thanks!!

Another option is to pass args as an array  
:abc =\> 123

---

<div class="post-metadata">

**Author:** ![macario](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b4bc9f/32.png) [@macario](https://www.ruby-forum.com/u/macario)\
**Post date:** [July 15, 2008, 7:40am UTC](https://www.ruby-forum.com/t/proc-argument-names-instead-of-arity/143094/4 "2008-07-15T07:40:38Z")

</div>

Roger P. wrote:

> Appears that there is.  
> ~ sudo gem install ParseTree
> 
> > > class A; def go(b); end; end  
> > > args = ParseTree.translate(A, :go)[2][1][1]  
> > > =\> [:args, :b]
> 
> Only works with MRI.  
> Been using it recently for an auto named variable generator.  
> GL.  
> -R

I will check it out

I want to get the arg names for a block passed as an argument, I will  
check the API. Thanks!!

---

<div class="post-metadata">

**Author:** ![macario](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b4bc9f/32.png) [@macario](https://www.ruby-forum.com/u/macario)\
**Post date:** [July 16, 2008, 6:38am UTC](https://www.ruby-forum.com/t/proc-argument-names-instead-of-arity/143094/5 "2008-07-16T06:38:19Z")

</div>

Macario O. wrote:

> Roger P. wrote:
> 
> > > I want to get the arg names for a block passed as an argument, I will  
> > > check the API. Thanks!!
> > 
> > Another option is to pass args as an array  
> > :abc =\> 123
> 
> Yeah, extracting the arg names is the sclang solution but is not the  
> only plausible one, thanks.

Anyway I would like get the arg names for a proc. Is it doable with  
parsetree. I am googling about it.

---

<div class="post-metadata">

**Author:** ![macario](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b4bc9f/32.png) [@macario](https://www.ruby-forum.com/u/macario)\
**Post date:** [July 16, 2008, 8:02am UTC](https://www.ruby-forum.com/t/proc-argument-names-instead-of-arity/143094/6 "2008-07-16T08:02:01Z")

</div>

Macario O. wrote:

> Macario O. wrote:
> 
> > Roger P. wrote:
> > 
> > > > I want to get the arg names for a block passed as an argument, I will  
> > > > check the API. Thanks!!
> > > 
> > > Another option is to pass args as an array  
> > > :abc =\> 123
> > 
> > Yeah, extracting the arg names is the sclang solution but is not the  
> > only plausible one, thanks.
> 
> Anyway I would like get the arg names for a proc. Is it doable with  
> parsetree. I am googling about it.

Found this:

[http://rubyforge.org/forum/forum.php?forum\_id=9485](http://rubyforge.org/forum/forum.php?forum_id=9485)

adds a to\_sexp method to proc

---

<div class="post-metadata">

**Author:** ![macario](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b4bc9f/32.png) [@macario](https://www.ruby-forum.com/u/macario)\
**Post date:** [July 15, 2008, 8:14am UTC](https://www.ruby-forum.com/t/proc-argument-names-instead-of-arity/143094/7 "2008-07-15T08:14:05Z")

</div>

Roger P. wrote:

> > I want to get the arg names for a block passed as an argument, I will  
> > check the API. Thanks!!
> 
> Another option is to pass args as an array  
> :abc =\> 123

Yeah, extracting the arg names is the sclang solution but is not the  
only plausible one, thanks.
