From: Mark Hubbart Date: 2005-11-10T04:34:48+09:00 Subject: Re: method_missing On 11/9/05, Dirk Meijer wrote: > hi, > thanks, the NoMethodError catching works :-) > and Mark, the argument has to be sent, otherwise the existing methods > wouldn't get the arguments either (it looks like this: > eval("Module::#{command}(#{argument})") ahh :) that was it. Where command = "foo" and argument = "bar": eval("Module::#{command}(#{argument})") evaluates the code: Module::foo(bar) ... where bar is not a string, it's a method call :) Instead of the evil eval, you might try: Module.__send__(command, argument) This will work in the way you expect. Also, I agree that catching the error is the best way to deal with the situation. Though method_missing is really cool :) cheers, Mark > but the problem is solved then :-) > greetings, Dirk. > > 2005/11/9, Mark Hubbart : > > > > On 11/9/05, Dirk Meijer wrote: > > > hi everyone, > > > i've got a small problem and can't figure out how to solve it. > > > in my program, you can enter commands, and then it checks if those > > commands > > > exist within a module.. > > > if the command does not exist, it should tell the user that, this gets > > me to > > > this: > > > def method_missing(method,*trash) > > > print "Command #{method} not found!\n" > > > end > > > but when the user enters a command with an argument (only one argument > > is > > > read), it prints the following: > > > Command not found! > > > Command not found! > > > which doesn't look very nice.. how would i solve this? > > > > It might help if you post some more of the code, especially that > > related to taking the user's input and calling the methods. > > > > My guess is that it lies in that area; it looks like maybe you are > > accidentally "send"ing the argument as a method call. > > > > cheers, > > Mark > > > > > greetings, Dirk. > > > > > > > > > > > >