I have been through all the documents on Ruby C extensions that I can find to no good end.
Is there a complement to the Init_...
method of initializing a C extension that is called as the interpreter exits?
There is no general "interpreter exiting" hook. But Ruby does garbage-collect everything on a normal exit, including Module and Class objects, and there is a way to hook object garbage collection. So you could adapt the following code that applies equally to Ruby interpreted objects or those defined by a C library:
module MyLib
end
ObjectSpace.define_finalizer( MyLib, proc { puts "MyLib unloaded" } )
You will need to take care to avoid assumptions that other Module or Class objects you expect to have available still exist when running this code, you are not in full control of the order in which this will get called on program exit.