From: "Hal E. Fulton" Date: 2002-11-04T07:50:20+09:00 Subject: Re: Dynamic message dispatch? ----- Original Message ----- From: "Yukihiro Matsumoto" To: "ruby-talk ML" Sent: Sunday, November 03, 2002 4:39 PM Subject: Re: Dynamic message dispatch? > Hi, > > In message "Re: Dynamic message dispatch?" > on 02/11/04, Paul J. Sanchez writes: > > | me> Suppose I have methods foo and bar. How can I read a string > | me> from ARGV or input and turn it directly into the message > | me> dispatch? > | > |Sorry, I meant to say "How can I read 'foo' or 'bar' as a string > |from...". I'm not asking how to do the input, I can't figure out how > |to convert a string into a method invocation on the fly. > > send? > > self.send("print", "foo\n") It seems to me that methods such as #send and #define_method offer safer/saner alternatives to eval. In that vein: Suppose I had a config file with lines of the form: var_name = string_or_number It is tempting simply to read each line and do an eval in order to grab this information (or perhaps even do a require). But this is not really safe if we assume someone could accidentally/purposely put something ugly in the file. Is there a better way to handle lines of the form country="United States" and size=256 without building a parser? And BTW, are you still in North America??? :) How did it all go? Hal