From: DMisener Date: 2008-09-23T03:36:57+09:00 Subject: Re: at_exit handler *except* for fatal runtime error On Sep 22, 1:27 pm, "ara.t.howard" wrote: > On Sep 22, 2008, at 9:51 AM, DMisener wrote: > > > Simple problem: > > > Create a tentative output working file.  If the program exits > > "cleanly" then rename the work file > > to its "final" name.  If not leave the work file for possible > > examination. > > > Ideally this File.open_tentative_output_file would be plug > > "compatible" with the simple File.open > > (i.e. support modes and blocks). > > class TentativeFile >    Ext = 'tentative' > >    def open path, *a, &b >      super "#{ path }.#{ Ext }", *a, &b >    end > >    def close >       final = path.to_s.sub %r/[.]#{ Ext }$/, '' >       super >    ensure >      File.rename path, final unless $! >    end > end output=TentativeFile.new.open('temp.tmp','w') output.puts 'Thanks' without an explict close doesn't automatically rename the file to its proper form. With "regular" File.open ... the file is automatically closed without need of explicit close. That was the behaviour I was trying to emulate. I'm starting to think this "frill" is a lost cause.