From: Matthieu TC Date: 2007-05-26T15:05:43+09:00 Subject: Re: Newbie question: variable method call --0-1931424544-1180159142=:53284 Content-Type: text/plain; charset=ascii Assuming your variable contains a string, try this: method_name = "feed" pet.send(method_name) -mats ----- Original Message ---- From: Kal Starkis To: ruby-talk ML Sent: Saturday, May 26, 2007 3:50:41 PM Subject: Newbie question: variable method call Is there a way to use the value of a variable to call a method of that name? For example, rather than use the following code to determine which method of the 'pet' object to call: if action == "feed" pet.feed elsif action == "walk" pet.walk elsif action == "pat" pet.pat #etc... end I'd rather just do something like this: pet.action The problem is, Ruby thinks I am trying to call a method named 'action', instead of evaluating the variable and using its value (e.g. 'feed'). -- Posted via http://www.ruby-forum.com/. --0-1931424544-1180159142=:53284--