From: Robert Klemme Date: 2004-07-23T20:17:07+09:00 Subject: Re: File.new("file.ext", "w").write data "Erik Veenstra" schrieb im Newsbeitrag news:pan.2004.07.22.19.34.08.348106@erikveen.dds.nl... > > Consider... > > File.new("file.ext", "w").write data > > Is this safe? When will the file be closed? For IO it's said: > "I/O streams are automatically closed when they are claimed by > the garbage collector." Is this true for files as well, (File > is a subclass of IO)? Yes. But you won't know when it is closed. That can be a nuisance if you have to open the same file multiple times - it may work or not, depending on the timing of GC. But that's usually a bad choice. > I know you can do... > > File.open("file.ext", "w"){|f| f.write data} > > ..., but the first one is shorter and better readable. .... and less safe. Use the block form, that's IMHO the most appropriate thing to do here. It's not much longer also. Regards robert