From: Josh Cheek Date: 2010-11-09T02:36:50+09:00 Subject: Re: Comparing/search struct array --20cf300fa9e99d510304948e1108 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 2010/11/8 Jes=FAs Gabriel y Gal=E1n > On Mon, Nov 8, 2010 at 6:14 PM, Josh Cheek wrote: > > 2010/11/8 Szabolcs T=C3=B3th > > f =3D File.open("report.output", 'r').each {|line| > >> if line =3D~ /MST Revenue/ > >> > >> > > Tricky to find this one in the docs, its actually under IO rather than > File > > http://ruby-doc.org/core/classes/IO.html#M002239 "If the optional code > block > > is given, it will be passed *io* as an argument, and the > > IOobject will automatically > > be closed when the block terminates." So you can > > let File close the file for you (this is considered a best practice, > since > > it does certain things to ensure this will happen, even if an error is > > raised) > > > > File.open 'report.output' do |file| > > file.each do |line| > > ... > > end > > end > > If you are not doing anything else with the file apart from reading > the lines you could also do: > > File.foreach("report.output") do |line| > ... > end > > Jesus. > > Thanks, I was looking for that, but couldn't remember what it was called I found each_line in the docs, and thought that's what I had remembered. --20cf300fa9e99d510304948e1108--