From: Robert Dober Date: 2008-03-08T00:10:44+09:00 Subject: Re: Meta Programming Question On Fri, Mar 7, 2008 at 8:37 AM, Pit Capitain wrote: > 2008/3/5, MohsinHijazee : > > > If I have a hash like this which contains code snippets as strings, > > How can I execute them? Moreover consider also that the second code > > snippet uses the value of the variable assigned in the first one. > > Mohsin, as others have mentioned you should probably use other > libraries, but just in case you want to continue to eval strings, > there's no problem with assigning variables and using them later: > > irb(main):001:0> eval "var = 123" > => 123 > irb(main):002:0> eval "2 * var" > => 246 > irb(main):003:0> > > Regards, > Pit > > This does not really serve a lot as var is visible in the eval binding *only*. E.g. puts var # will not output 123, not even 42 ;) Cheers Robert -- http://ruby-smalltalk.blogspot.com/ --- Whereof one cannot speak, thereof one must be silent. Ludwig Wittgenstein