On 2006.01.18 11:40, Logan Capaldo wrote:
>
> On Jan 17, 2006, at 8:30 PM, Didier Prophete wrote:
>
> >The best I can do is get a handle to the 'method' object. Something
> >like:
> > meth = self.method(:f1)
> >
> >But I am stuck there... I would need something like:
> > meth.arg_list
> >which would return [ :arg1, :arg2 ], or something like that.
>
> I don't believe there is a way to get the argument names from inside
> ruby.
Slightly off-topic, but there is :)
def foo(a, b, c)
local_variables.each {|var| puts "#{var}: #{eval var}"}
end
foo 1, 2, 3
> ... Can you define these methods (f1 and friends) to take a hash
> instead?
>
> eg:
> f1(:arg1 => 1, :arg2 => 2)
>
> If you can't do this (you didn't write the functions) perhaps you
> need a more robust abstraction, something like a class called
> Invocation, or Call or something.
>
> eg
>
> class Call
> attr_accessor :target, :method_name, :arguments
> def argument_names
> ... # insert code here to list the names of the arguments
> end
> end
>
> Of course you'll still need a way to generate this list. Perhaps with
> RDoc. THis is a little complicated though, ideally you would simply
> have the functions take a hash as its single parameter as I
> mentioned. Still not quite sure what you are asking.
E