Does RM support at_exit in Ruby?

Now, I may be doing it wrong, but Ruby has at_exit, which lets you run something when the program closes. Does RM, specifically Ace, support this? I tried testing it with 

at_exit { puts "Closing!"; sleep(3) }but it didn't work. I'm wondering if I somehow managed to get something so simple wrong, or if RM doesn't support the function in Ruby at all. For anyone wondering about it, it's in Ruby's Kernerl, so it should work, right?
Try creating a file. Maybe the output stream have been changed or closed at that time.
That was a good suggestion, but unfortunately no, it's not working there either. I suppose it's possible RM closes the Ruby runtime with exit!, which doesn't call at_exit hooks, but that'd be kind of stupid, in my opinion. Any other ideas?
take off the the "at_" part and use these

begin { block }

end { block }
take off the the "at_" part and use these


begin { block }


end { block }
I don't understand what you mean but I'm assuming Zalerinian wants to be able to execute code if I hit Alt+F4 or the X button in the corner of the window. Would this accomplish it?
That was a good suggestion, but unfortunately no, it's not working there either. I suppose it's possible RM closes the Ruby runtime with exit!, which doesn't call at_exit hooks, but that'd be kind of stupid, in my opinion. Any other ideas?
i try using script call on event: (assuming quit game could use exit!)

at_exit {  File.delete("Notebook/test delete.txt")}Kernel::exitbut it still don't execute at_exit at all...

it's like the Kernel::exit itself did not call the at_exit.

Original thread: https://forums.rpgmakerweb.com/threads/does-rm-support-at_exit-in-ruby.19208/