I have a variable and I want to call a method with the name of the variable example: method_variable = "sum" def sum .... end How can i do that? thank...
on 2007-01-19 15:44
on 2007-01-19 16:18
Daniel PÃ©rez wrote: > I have a variable and I want to call a method with the name of the > variable > example: > method_variable = "sum" > > def sum > .... > end > > How can i do that? > > thank... self.send(method_variable) Alan
on 2007-01-19 16:24
use the Object.send instance method class Klass def sum(a, b) a + b end end k = Klass.new m = "sum" k.send m.to_sym, 1, 2 => 3 Chris