James Gray
1/18/2006 1:43:00 PM
On Jan 18, 2006, at 6:48 AM, Kevin Olbrich wrote:
> Lots of good responses here, but the one that turns out to be the
> easiest is...
>
> def func(param)
> some_value = 42
> value = eval %Q{%Q{#{param}}}
> end
>
> func('my number is #{some_value}') #=> 'my number is 42'
What you really want here is ERB:
>> require "erb"
=> true
>> def expand( template )
>> some_value = 42
>> ERB.new(template).result(binding)
>> end
=> nil
>> expand "My number is <%= some_value %>."
=> "My number is 42."
James Edward Gray II