From: "Jesús Gabriel y Galán" Date: 2010-08-20T20:43:32+09:00 Subject: Re: function call using reflection On Fri, Aug 20, 2010 at 1:12 PM, Rajarshi Chakravarty wrote: > Hi, > I get each part of the following command in a string at runtime > Mod1::Util.parser1("log.txt") > > So I have the following strings: > s1 = "Mod1" > s2 = "Util" > s3 = "parser1" > s4 = "log.txt" > > Now I want to prepare the command and execute it at runtime. > > Object::const_get(s1 + "::" + s2 + "." + s3 + "(\"" + s4 + "\")") > does not work. If you know the first one is a module and the second a class, you could try: irb(main):001:0> module A irb(main):002:1> class B irb(main):003:2> def parse(param) irb(main):004:3> puts "parsing #{param} ..." irb(main):005:3> end irb(main):006:2> end irb(main):007:1> end => nil irb(main):008:0> s1 = "A" => "A" irb(main):009:0> s2 = "B" => "B" irb(main):010:0> s3 = "parse" => "parse" irb(main):011:0> s4 = "filename.txt" => "filename.txt" irb(main):014:0> m = Object.const_get(s1) => A irb(main):015:0> c = m.const_get(s2) => A::B irb(main):017:0> c.new.send(s3, s4) parsing filename.txt ... Jesus.