T
Taisuke Yamada
Hi.
I'm trying to find a clean way to expand string with "#{...}".
What I want to do is essentially as follows:
data = 123
expr = 'data = #{data}'
puts dosomething(expr)
and get 'data = 123' as a result. Actual content of 'expr' can
be anything, as long as it is a String object.
I came up with following:
puts eval(%Q{"#{expr.gsub('"', '\"')}"})
But this is ugly, and I'm wondering if there's some other,
cleaner way to do the same thing.
Can anyone enlighten me?
Best Regards,
I'm trying to find a clean way to expand string with "#{...}".
What I want to do is essentially as follows:
data = 123
expr = 'data = #{data}'
puts dosomething(expr)
and get 'data = 123' as a result. Actual content of 'expr' can
be anything, as long as it is a String object.
I came up with following:
puts eval(%Q{"#{expr.gsub('"', '\"')}"})
But this is ugly, and I'm wondering if there's some other,
cleaner way to do the same thing.
Can anyone enlighten me?
Best Regards,