Xavier Noria
8/26/2007 9:48:00 AM
On Aug 26, 2007, at 11:20 AM, Thomas Worm wrote:
> a = 5
> b = "#{a}"
> puts b
>
> a = 6
> puts b
>
> Returns:
> 5
> 5
>
> which is clear to me, why. But is there a way to define such a
> string and
> interpolate it at a later time?
You normally use a templating system, for example:
require 'erb'
b = ERB.new("a is <%= a %>")
a = 5
puts b.result(binding) # -> a is 5
a = 6
puts b.result(binding) # -> a is 6
-- fxn