From: ptkwt@...1.aracnet.com (Phil Tomson) Date: 2001-10-31T18:16:08+09:00 Subject: [ruby-talk:23929] Re: question about string interpolation and '#{}' In article <006601c161e5$e8ade4c0$0300a8c0@austin.rr.com>, Hal E. Fulton wrote: >----- Original Message ----- >From: Phil Tomson >Newsgroups: comp.lang.ruby >To: ruby-talk ML ; >Sent: Wednesday, October 31, 2001 2:16 AM >Subject: [ruby-talk:23924] Re: question about string interpolation and '#{}' > > >> In article <005501c161e0$3b6f4100$0300a8c0@austin.rr.com>, >> Hal E. Fulton wrote: >> >----- Original Message ----- >> >From: Phil Tomson >> >Newsgroups: comp.lang.ruby >> >To: ruby-talk ML ; >> >Sent: Wednesday, October 31, 2001 1:36 AM >> >Subject: [ruby-talk:23918] question about string interpolation and '#{}' >> > >> > >> >> I think I'm really trying to do some strange things with string >> >> interpolation and I'm not sure if what I want to do is completly >> >> possible... >> > >> >Probably a silly question on my part... it's 1:46 am in my timezone -- >> >but why are you doing eval str.inspect rather than just eval str? >> > >> >> Good question. Because not all of the stuff in the strings to be eval'ed >> is Ruby code, only the stuff between #{ and }. > >How about something like this: > >s2 = str.gsub(/"/, '\"') >s3 = '"'+s2+'"' >eval s3 > Close... actually, I needed to do: s1 = str.gsub(/\\/,'\&\&') #in case there is some deliberate '\n' in the #file s2 = s1.gsub(/"/, '\"') s3 = '"'+s2+'"' eval s3 I think this will cover all the cases... Thanks. Phil