From: Dave Burt Date: 2006-05-02T09:17:56+09:00 Subject: Re: getting the name of arguments a method takes Guest wrote: > Didier Prophete wrote: >> I am wondering if there is a way to programatically get the name of the >> arguments a function take. >> >> Say, I have this code: >> class MyClass >> def my_fct(a, b, c) >> end >> end >> >> Now, I can easily get a handle to the method 'my_fct' using: >> mc = MyClass.new >> meth = mc.method(:my_fct) >> >> But how do I get to the list of arguments of 'my_fct' ? I couldn't find >> anything like: >> meth.arg_list >> which would return [ :a, :b, :c ], or something like that. >> >> Is this even possible in ruby ? >> >> -Didier > > i also would like to do this. anybody know if it's possible, and also > getting arg names from a proc? if so it would be very handy for > metaprogramming. The short answer: no, it's not possible. What do you want it for? There's always this way, though: def method_arg_names(method_name, file) File.read(file)[/def #{Regexp.escape method_name}(.*(\)|$))/, 1] end p method_arg_names("method_arg_names", $0) #=> "(method_name, file)" Cheers, Dave