From: Eero Saynatkari Date: 2006-09-28T07:31:38+09:00 Subject: Re: Idiomatic file snarf --f5QefDQHtn8hx44O Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2006.09.28 07:02, Tim Bray wrote: > I want to open a file, suck the contexts into a variable and close it =20 > again. I suppose I could IO#each and glue the lines together. The 'correct' way is: text =3D File.read file_name =20 > Currently I have >=20 > f =3D File.new(fname) > text =3D f.read > f.close A better way for the above is this: text =3D File.open(file_name) {|f| f.read} --f5QefDQHtn8hx44O Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (FreeBSD) iD8DBQFFGvtU7Nh7RM4TrhIRAkEoAKDNT62kc4gtJtTCvgD/sNFhS2BhnACg6DXK vLTGIVUVD8kDAQ2c1LW+eOA= =sl18 -----END PGP SIGNATURE----- --f5QefDQHtn8hx44O--