From: Harry Kakueki Date: 2007-05-23T11:35:20+09:00 Subject: Re: Substituting variables in a method On 5/23/07, Michael W. Ryder <_mwryder@worldnet.att.net> wrote: > Rick DeNatale wrote: > > On 5/22/07, Harry Kakueki wrote: > > > >> str4 = str3.gsub("#{str1}","#{str2}") > > > > The string interpolation is completely unnecessary, this is the same as: > > str4 = str3.gsub(str1, str2) > > > > > How does one know when to use string interpolation and when it isn't > needed? I know that if I want to put a variable in the middle of a > string I have to use interpolation so I thought I also needed something > like that in this case as I didn't want to convert c's to d's. > > OK, I gave a bad example. Maybe this is a little better. str1 = "str1 string. " str2 = "more stuff" str3 = str1.gsub(str1,str2) str4 = str1.gsub("str1","str2") str5 = str1.gsub("str1","Now #{str2}") p str1 p str2 p str3 p str4 p str5 Harry -- A Look into Japanese Ruby List in English http://www.kakueki.com/