From: Jack Dempsey Date: 2002-01-12T03:19:03+09:00 Subject: gsub: arrays as parameters This is a multi-part message in MIME format. ------=_NextPart_000_0017_01C19AA2.259E5F00 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit I wrote this and it works well for me. I wanted to see what others thought, and ask if anyone (Matz?) knows the pros and cons of making a change like this to gsub. class String def gsubx!(regex,replace) regex.each_with_index do |x,i| self.gsub!(x,replace[i]) end end def gsubx(regex,replace) str = self.dup regex.each_with_index do |x,i| str.gsub!(x,replace[i]) end str end end Jack "On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of idas that could provoke such a question. --Charles Babbage" ------=_NextPart_000_0017_01C19AA2.259E5F00 Content-Type: text/html; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable

I wrote this and it works well for me. I wanted to = see what others thought, and ask if anyone (Matz?) knows the pros and cons of = making a change like this to gsub.

 

class = String

   = def = gsubx!(regex,replace)

      regex.each_with_index do = |x,i|

        self.gsub!(x,replace[i])       &nbs= p;    

      end

   = end

   =

   = def = gsubx(regex,replace)

      str =3D self.dup

      regex.each_with_index do = |x,i|

        str.gsub!(x,replace[i])       &nbs= p;    

      end

      str   =

   = end

 

end

 

Jack

 

"On two occasions I have been = asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the = machine wrong figures, will the right answers come out?' I am not able rightly = to apprehend the kind of confusion of idas that could provoke such a = question. --Charles Babbage"

 

------=_NextPart_000_0017_01C19AA2.259E5F00--