[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Proc argument names instead of arity

Macario Ortega

7/15/2008 4:33:00 AM



Hi, i am trying to make a SuperCollider(http://www.audio...)
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?
--
Posted via http://www.ruby-....

5 Answers

Roger Pack

7/15/2008 5:21:00 AM

0


> 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
--
Posted via http://www.ruby-....

Macario Ortega

7/15/2008 5:36:00 AM

0

Roger Pack 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!!
--
Posted via http://www.ruby-....

Roger Pack

7/15/2008 6:03:00 AM

0


> 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
--
Posted via http://www.ruby-....

Macario Ortega

7/15/2008 6:09:00 AM

0

Roger Pack 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.
--
Posted via http://www.ruby-....

Macario Ortega

7/16/2008 4:34:00 AM

0

Macario Ortega wrote:
> Roger Pack 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.

--
Posted via http://www.ruby-....