From: Phrogz Date: 2007-11-15T05:10:13+09:00 Subject: Re: "once" meta-method without "module_eval" (Pickaxe) On Nov 13, 11:23 pm, Greg Weeks wrote: > Am I right to think that eval-ing strings is retro? My first dynamically-typed, runtime-interpreted scripting language was JavaScript. In JavaScript, eval is considered a bad idea. Loading a string of JavaScript code compiles it to bytecode and then executes the byte code. Hitting an eval() call in the middle of a program requires booting up the lexer and bytecode compiler again, to handle that one string, before it can be run. It's inefficient, and almost never needed. I gather the same is not true in Ruby currently. I think (but may be horribly wrong) that this is not so much because of some excellent implementation of eval, but a because everything is in the same slow pool of interpretation. I'm totally guessing, but I would suspect that at some point in Ruby's runtime future, startup optimizations/compilations will happen once only. If this is true (and I know very little about virtual machines and bytecodes and the actual implementation, so I could be wrong), then I would suspect that eval of a string (not a block) will incur undesirable overhead. For these reasons (my history with eval in JS and my suspicion that it may become undesirable from a performance standpoint) I personally never eval strings.