On Nov 15, 2010, at 8:11 AM, Werner Schuster (murphee) wrote:
> On 11/15/10 4:58 PM, Guilherme Silveira wrote:
>> Thanks Roland,
>>
>> ParseTree and Ripper are file source parsers,
> That's incorrect for ParseTree, which essentially just turned MRI's AST into
> a Ruby data structure, ie. it worked at runtime without looking at the source.
> Merb had a feature, long ago, called action arguments, which used ParseTree
> to get at argument names (the docu link is gone, but I wrote about it here
> http://www.infoq.com/news/2009/07/ruby192-preview1-rubyversions )
>
> There's a JRuby version of ParseTree (oddly named 'jParseTree') that I wrote
> a few years ago, but it hasn't been updated in quite a while, and probably
> doesn't run in its current state (unless the JRuby AST has been stable for
> the last 3 years).
>
> Hm... come to think of it... this
> http://www.infoq.com/news/2009/07/ruby192-preview1-rubyversions mentions
> that Ruby 1.9.2 might get Method#parameters, which should do what you want.
> No idea about the status of this right now;
>
I implemented it earlier this year.
$ jruby --1.9 -S irb
irb(main):001:0> lambda {|arg1, arg2, arg3=true, *rest|}.parameters
=> [[:req, :arg1], [:req, :arg2], [:opt, :arg3], [:rest, :rest]]
irb(main):002:0> def func(arg1, arg2, arg3=true, *rest); end
=> nil
irb(main):003:0> method(:func).parameters
=> [[:req, :arg1], [:req, :arg2], [:opt, :arg3], [:rest, :rest]]
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email