From: Tim Hunter Date: 2007-06-27T08:29:30+09:00 Subject: Re: Arguments into method calls? Torrey Slattery wrote: > I'm working on a program that takes user input via command line, then > calls whatever method is related to that input text. > > For instance, if they type /help it calls the method help, if they type > /quit it calls the method quit, /time calls time, etc. > > Essentially, if they type in something with a slash, I want the program > to interpret it as a special command, strip off the / and calls a method > with the leftover text. > > I can think of a clunky way to do this using a ton of if/elsif clauses > and matching regular expressions, but as I eventually plan to have over > a hundred commands, that doesn't seem pleasant to write at all. > > Is there a cleaner way to do this? > > Check out the __send__ method, which lets you call a method whose name is in a variable: obj.__send__(method_name, args) -- RMagick OS X Installer [http://rubyforge.org/projects/rmagick/] RMagick Hints & Tips [http://rubyforge.org/forum/forum.php?forum_id=1618] RMagick Installation FAQ [http://rmagick.rubyforge.org/install-faq.html]