From: Paolo Capriotti
Date: 2006-01-18T19:09:39+09:00
Subject: Re: Delayed quote expansion
On 1/18/06, Kevin Olbrich wrote:
[snip]
> I would like to do something like this...
>
> def func(param)
> test = 42
> puts param.quote_substitution
> end
>
> func('my number is #{test}') #=> "my number is 42"
Try this:
class String
def evaluate(*args)
eval inspect.gsub(/\\#/, '#'), *args
end
end
def func(str)
x = 42
str.evaluate(binding)
end
puts func('the answer is #{x}')
--
Paolo