From: Eko Budi Setiyo Date: 2005-01-26T09:32:50+09:00 Subject: Re: String.str_replace ???? Robert Klemme wrote: >"E S" schrieb im Newsbeitrag >news:20050125052315.WKZL2811.fep31-app.kolumbus.fi@mta.imail.kolumbus.fi... > > > >>B) You can use Enumerable: >> >>class String >> def str_replace(what, with) >> s = self.collect do |c| >> with if c === what >> end >> end >>end >> >> > >I don't think this will work as String#each does not yield single >characaters but "lines". > > > You are right, it doesn't But I already manage to make String.str_replace (case sensitive) and String.str_ireplace (incase sensitive) pass all my unit test I already check there is not same function yet build in Ruby object Thanks a lot for giving me some idea regards Eko >>>a=<>> >>> >foo >bar >end >EOS >=> "foo\nbar\nend\n" > > >>>a.each {|x| p x} >>> >>> >"foo\n" >"bar\n" >"end\n" >=> "foo\nbar\nend\n" > > >>>a.collect {|x| p x; :x} >>> >>> >"foo\n" >"bar\n" >"end\n" >=> [:x, :x, :x] > >Regards > > robert > > >