Proc argument names instead of arity

Hi, i am trying to make a SuperCollider(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?

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

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

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!!

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.

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

adds a to_sexp method to proc

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs