From: Didier Prophete Date: 2006-01-20T18:04:18+09:00 Subject: Re: invalid_arity method similar to method missing ? Logan, > I don't believe there is a way to get the argument names from inside > ruby. yeah... I am afraid this is impossible in ruby... > Can you define these methods (f1 and friends) to take a hash > ... > mentioned. Still not quite sure what you are asking. ahah... well, thanks for helping me anyway. I really appreciate that. Let me try to explain what my goal was: Think about how controllers are handled in rails for a second. You end up having methods after methods which are like: def meth1 name = params[:name] data = params[:data] ... end def meth2 arg1 = params[:arg1] arg2 = params[:arg2] arg3 = params[:arg3] ... end Well, this is a little tedious, so I wanted to instead declare these as: def meth1(name, data) ... end def meth2(arg1, arg2, arg3) ... end (see how the arguments are passed to the methods rather than being manually extracted from the 'params' object) Well, it turns out that these controller methods are always called from the same place, using: send(action_name) (where here, action_name is :meth1, or :meth2) Now, in order to introduce my change and keep the framework working, I would want to replace this little piece of code by something like: arg_names =
args = arg_names.map { |name| params[name] } send(action_name, *args) Or something like that. The idea being that the caller extracts the parameter values from the 'params' object and invoke the appropriate method with these parameters... Now, because getting the argument names of a method might not be possible in ruby, this whole thing will not work... But hey, thanks for helping me (thank also to Eero for his slightly off-topic comment :-) -Didier -- Posted via http://www.ruby-forum.com/.