From: Robert Klemme Date: 2008-09-23T03:41:48+09:00 Subject: Re: at_exit handler *except* for fatal runtime error On 22.09.2008 17:56, DMisener wrote: > On Sep 19, 6:57 am, Robert Dober wrote: >> On Thu, Sep 18, 2008 at 10:07 PM, Robert Klemme> Oh, come on. >> You can easily use that information to build what you want. > > Actually inverting the logic isn't that easy (at least for me) > >> Hmm maybe not Robert, my feeling is that they should not do what they >> are doing in the at_exit block. > > I'm certainly not married to the the at_exit approach. > >> OP can you give us the rationale behind this design. At first sight I >> believe you should do what you want in the main script. Look at Ara's ideas e.g. > > 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). > > Perhaps I'm trying to make life "too easy" for the application > programmer by eliminating the need for > an explicit File.close_all_pending_tentative_file routine. It rather seems that you're making *your* life too hard. :-) > That is > really all that I am trying to achieve with the > at_exit{} code. One less step to remember. But perhaps the > implementation complexity isn't worth it. Why do you need at_exit for this - especially if you want to be compatible to File.open? def File.open_tentative_output_file(tmp, final, mode = "w", &b) raise "Need a block" unless b File.open(tmp, mode, &b) File.rename tmp, final end Done. Cheers robert