From: Jack Dempsey Date: 2002-01-06T05:44:00+09:00 Subject: [ruby-talk:30301] gsub with arrays This is a multi-part message in MIME format. ------=_NextPart_000_0026_01C195FD.D31AD4A0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable To any who might find it useful: class String def gsubx!(regex,replace) regex.each_with_index do |x,i| self.gsub!(x,replace[i]) =20 end end =20 def gsubx(regex,replace) str =3D self.dup regex.each_with_index do |x,i| str.gsub!(x,replace[i]) =20 end str =20 end end And to the person who gave that great Enumerable each_send method, I = agree that a place to store and trades snippets like this would be = great. Perhaps if we keep talking about it and trying to make strides = something will come of it. Jack ------=_NextPart_000_0026_01C195FD.D31AD4A0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
To any who might find it = useful:
 
class String
   def=20 gsubx!(regex,replace)
      = regex.each_with_index do=20 |x,i|
       =20 self.gsub!(x,replace[i])        &= nbsp;   =20
      end
   = end
  =20
   def = gsubx(regex,replace)
      str=20 =3D self.dup
      regex.each_with_index do=20 |x,i|
       =20 str.gsub!(x,replace[i])        &n= bsp;   =20
      end
      = str  
   end
end
 
And to the person who gave that great = Enumerable=20 each_send method, I agree that a place to store and trades snippets like = this=20 would be great. Perhaps if we keep talking about it and trying to make = strides=20 something will come of it.
Jack
------=_NextPart_000_0026_01C195FD.D31AD4A0--