From: Robert Klemme Date: 2009-08-18T16:35:51+09:00 Subject: Re: while !file.eof? 2009/8/18 botp : > On Mon, Aug 17, 2009 at 2:50 PM, Robert > Klemme wrote: >> You're not closing the file handle properly. :-) >> > > i was leaning on the op's example... :)  For the record, when it comes > to file handling, i do not even do shortcuts ;) :-) > i think i have a question for you, cool ruby hacker robert: > if  i do something like, > >    File.open(foo).each do >       blah >    end > > will ruby be able to cleanup the orphaned file handle? Probably yes. But: it will certainly be later than necessary (when a finalizer is run which may be even as late as process exit). Plus, if you open the file again in the same interpreter instance you may face strange effects. That may be not so important for files which are read only, but it can create serious issues when writing files. My stance is this: release resources as soon as possible, especially if it is as easy as with files. >> Better: >> >> File.foreach "maillog" do |line| > > i am not a fan of foreach because i do not like the method name as > used... it's like saying "for each file"?? > but that is just me... I would aesthetics not come in my way that far. But even if: you can always do class File class <