From: Chris Bailey Date: 2008-08-29T05:59:41+09:00 Subject: Re: Use a string as a method call Thank you everyone for the quick and helpful replies! I toyed around with all of the suggestions and decided the following would be the best choice in my application. def parse input = gets.downcase.chomp if $cmd_list.key?(input) send $cmd_list[input] else puts "#{input} is not a valid command." end end I have however ran into another problem and my limited knowledge of send (I hadn't heard of it until I read these replies) makes it difficult for me to debug. Some of my methods that worked perfectly before accessing them using send are no longer working properly. Consider the following. cmd_list = { 'north' => 'do_north' 'south' => 'do_south' 'n' => 'do_north' 's' => 'do_south' 'look' => 'do_look' } def cmd_north $PLROBJ.xcoord -= showMap() end def cmd_south $PLROBJ.xcoord += showMap() end def cmd_look showMap end If the user input is "look", the showMap method is called properly, and everything works as intended. However if north,south,n or s is typed into the system it fails to update the $PLROBJ variable but executes showMap() as usual and then crashes with the following error. ./commands.rb:16:in `-': nil can't be coerced into Fixnum (TypeError) from ./commands.rb:16:in `cmd_north' from bsud.rb:33:in `send' from bsud.rb:33:in `parse' from bsud.rb:58:in `main' from bsud.rb:63 $PLROBJ.xcoord and ycoord are initiated with a value of 5 and as far as I know there is nothing that would ever make them 'nil'. I have no idea what this problem is =( -- Posted via http://www.ruby-forum.com/.