jweirich / one.net writes: > ---------------------------------------------------------------------- > IV) Take advantage of blocks to do automatic closing > > ORIGINAL > begin > myfile = File.open('phonespec.txt', 'a') > # ... > ensure > myfile.close > end file = File.open > > > BETTER > 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 is, I expect the object reference will be gone, but does that ensure immediate destruction of the object and closing of any handles it may have? I expect this depends on how Ruby is destroying/garbage collecting such objects, right? This can be very important if your doing this in the midst of a file processing loop or any other processing that can eat up system resources (such as open file handles). -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l / fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/