"David Bolen" <db3l / fitlinxx.com> wrote in message
news:upu9onci7.fsf / ctwd0143.fitlinxx.com...
> jweirich / one.net writes:
>
[...]
> >         File.open('phonespec.txt', 'a') do |myfile|
> >           # ...
> >         end

> I'm curious, in the "better" case, does Ruby actually ensure that the
> file will be closed down at the OS level when the block exits?  That

It works by injecting the custom
do ... end
block into the source of the File.open function:

open file
yield (i.e. execute attached custom block)
close file

Therefore, the file is closed immediately after the block completes.
But I'm not sure what happens in case of an exception from inside the block.

Mikkel