From: Harry Kakueki Date: 2007-05-23T09:26:24+09:00 Subject: Re: Substituting variables in a method On 5/23/07, Michael W. Ryder <_mwryder@worldnet.att.net> wrote: > I am trying to figure out how to pass variables for the parameters to a > method. I want to do something like b = a.tr({c}, {d}) where 'c' is the > text to be matched and 'd' is the replacement text. Obviously the above > does not work, nor does b = a.tr(#{c}, ${d}). Is this even possible or > do I need to work out some regular expression to do the same thing. > What I am trying to do is have a method where I can say change all > periods to commas and commas to periods or change all *s to #s or ... > > I'm not sure if this is what you want, but.. str1 = "I am a string. " str2 = "You are not. " str3 = str1 + str2 str4 = str3.gsub("#{str1}","#{str2}") p str1 p str2 p str3 p str4 Harry -- A Look into Japanese Ruby List in English http://www.kakueki.com/