From: Daniel N Date: 2007-08-01T15:45:47+09:00 Subject: Re: Dynamic method call ------=_Part_13069_3775249.1185950751558 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On 8/1/07, Andrea Maschio wrote: > > I'm trying, for the purpose of making something similar to a grammar, to > do > this > > if_a_condition_is_true(condition, "method_name(arg1, arg2)") > > where > > def method_name(arg1, arg2) > #do something > end > > i've tried many way to implement > > def if_condition_is_true(condition , action) > #such as > eval(action) > #or > call self.method(action) > > end > > but noone worked, i've trying googling a bit but no chances. Have you got > an > idea on how to call dynamically a method, with his arguments? > > Thanks a lot folks > > -- > > Andrea Maschio > > http://www.superandrew.it > > A clever person solves a problem. > A wise person avoids it. > > Einstein To call an arbitrary method on an object use send object.send( :method_name_as_symbol [, arg1, arg2 ...] ) You can put that in an if statement etc or use object.send( :method ) if some_condition_is_true HTH Daniel ------=_Part_13069_3775249.1185950751558--