2009/8/18 botp [email protected]:
On Mon, Aug 17, 2009 at 2:50 PM, Robert
Klemme[email protected] 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,
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.
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
alias better_name foreach
File.better_name “foo” do |line|