From: Chad Perrin Date: 2011-07-15T10:12:45+09:00 Subject: Re: Is there a more efficient way to remove data from a string? --envbJBWh7q8WU6mo Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jul 15, 2011 at 09:54:48AM +0900, Chad Perrin wrote: >=20 > I'd probably do it something like this: >=20 > 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}.*/, '') } =2E . . 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. --=20 Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ] --envbJBWh7q8WU6mo Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (FreeBSD) iEYEARECAAYFAk4fkDEACgkQ9mn/Pj01uKXAyQCeOT9Qxc+TYB4jTillPs2e6DkC QGMAn15eo5/g1Frdy6YZ7idvx9qtyQhG =YlmA -----END PGP SIGNATURE----- --envbJBWh7q8WU6mo--