From: Sean O'Halpin Date: 2005-10-19T03:22:41+09:00 Subject: Re: Expression Interpolation from input "template string"? On 10/18/05, Kevin Ballard wrote: > > Perhaps you should simply try using eRB to evalute your templates, so > you could store "Hello, today is <%= msgDate %>"? Alternately, there's > probably some other templating code out there, or you could write your > own. I agree - there are too many gotchas with a roll-your-own string interpolation hack. Also, Rails uses erb as one of its template options so you would be compatible with that too. Here's some code to get you going: require 'erb' def erb(str, erb_binding) trim_mode = 1 erb = ERB.new(str, $SAFE, trim_mode) erb.result(erb_binding) end src = "Hello, today is <%= msg_date %>" msg_date = Time.now.strftime("%Y-%m-%d") puts erb(src, binding) #=> Hello, today is 2005-10-18 Regards, Sean