From: Eddie Catflap Date: 2011-07-15T10:20:40+09:00 Subject: Re: Is there a more efficient way to remove data from a string? Awesome stuff. Thanks to all that replied. It really is appreciated. Regards On Fri, Jul 15, 2011 at 2:12 AM, Chad Perrin wrote: > On Fri, Jul 15, 2011 at 09:54:48AM +0900, Chad Perrin wrote: >> >> I'd probably do it something like this: >> >>     ARGF.each_line do |line| >>       line.sub!(/#{reg1}.*/, '') >>       puts line >>     end > > Actually, I did too literal a translation of your code.  If I was writing > this from scratch, I probably would have done this instead: > >    ARGF.each_line {|line| puts line.sub(/#{reg1}.*/, '') } > > . . . or this: > >    ARGF.each_line do |line| >      puts line.sub(/#{reg1}.*/, '') >    end > > Which I would choose would depend on whether I felt it looked better > amidst my other code in the file on one line or three, and on whether I > expected I might need to add more lines later. > > -- > Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ] >