From: Peter Marks Date: 2008-04-05T08:56:56+09:00 Subject: Re: Using a string as executable code Phillip Gawlowski wrote: > And a question you might want to ask yourself: Do I want to be starring > on DailyWTF as "the developer before me"? Haha, point taken. I'm not familiar with metaprogramming or marshall. I'm looking into both. ara.t.howard wrote: did you read my code? I did, but I must not understand all of it. Sorry. ara.t.howard wrote: > why don't you spell out your exact problem and we can show you how. My db schema has a 'templates' table, a 'fields' table as well as a 'template_fields' join table that connects 'fields' to 'templates'. 'fields' needs to contain information to produce a customized text string for a particular object. Intuitively, I thought I needed to store string generating code as a string in 'fields' and execute it against my object. It was suggested I could do that like this: person.instance_eval field.code I use the resulting string and the field's 'name' to assemble a hash for each field connected to a template: rehash = {} for field in template.fields rehash[field.name] = person.instance_eval field.code end I then use the hash of generated strings and field names for a find and replace function. -- Posted via http://www.ruby-forum.com/.