From: "Michael W. Ryder" <_mwryder@...> Date: 2007-05-23T10:10:03+09:00 Subject: Re: Substituting variables in a method Harry Kakueki wrote: > 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 > That's what I was looking for. I would never have thought of enclosing the variables in double quotes. It also works for the .tr method. Is there some place that describes how to do these types of things or is it just a matter of experimenting or asking others?