From: Ara.T.Howard@... Date: 2005-04-22T23:24:33+09:00 Subject: Re: Clean way to dynamically expand string with "#{expression}"? On Fri, 22 Apr 2005, Taisuke Yamada wrote: > 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? this is a stupid question by why not simply use double quotes? data = 123 expr = "data = #{ data }" puts dosomething(expr) ?? -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | although gold dust is precious, when it gets in your eyes, it obstructs | your vision. --hsi-tang ===============================================================================