From: Austin Ziegler Date: 2008-11-10T23:50:05+09:00 Subject: [ruby-core:19779] Re: Proposal: Method#get_args On Mon, Nov 10, 2008 at 9:24 AM, Dave Thomas wrote: > On Nov 10, 2008, at 7:54 AM, Brian Candler wrote: >>> However, a class feels too heavyweight for the metaprogramming case, >>> while the anonymous tuple feels a little too lightweight and devoid >>> of context, at least to me. >> A Struct perhaps? You can always use to_a to get a tuple back. > Or an array of strings? > > def fred(a, b=2, *c, &block) > end > > method(:fred).arguments => ["a", "b=2", "*c", "&block" ] That feels a little better from my ability to understand it, but then programs which want to do metaprogramming have to do a lot of extra work (split on /=/; know that "*" means greedy, etc.). I was sort of thinking an array of Hashes, but that's not necessarily any lighter weight than a Struct or a dedicated class. method(:fred).arguments => [ { :name => :a }, { :name => :b, :default => 2 }, { :name => :c, :greedy => true }, { :name => block, :block => true } ] Playing with some other constructs: def wilma(a, *, c); end method(:wilma).arguments => [ { :name => :a }, { :name => nil, :greedy => true }, { :name => :c } ] def barney(a, b, c = b); end method(:barney).arguments => [ { :name => :a }, { :name => :b }, { :name => :c, :default => :b } ] I'm not really happy with the last -- because it conflicts with: def betty(a, b, c = :b); end method(:betty).arguments => [ { :name => :a }, { :name => :b }, { :name => :c, :default => :b } ] Or would that be: method(:betty).arguments => [ { :name => :a }, { :name => :b }, { :name => :c, :default => :":b" } ] Musings right now on how to express certain things. I think it could be useful to be able to get the symbolic information for a default parameter (even if it's a method call). -austin -- Austin Ziegler * halostatue@gmail.com * http://www.halostatue.ca/ * austin@halostatue.ca * http://www.halostatue.ca/feed/ * austin@zieglers.ca