Does at_exit work on a per-class basis? or is it global
The answer was:
global, and it’s equivalent to END{} block AFAIK
I believe this answer is true.
Now my question is … isn’t this a bit of a code smell in that when I
use many many different classes who some of them may use at_exit code,
this leads to a fragile and imperfect design?
Explanation:
I am writing on a pseudo-ruby shell (with a bash-like syntax).
I usually use ‘q’ to quit it.
Then suddenly one day, I required some files, one of which used at_exit,
and I had a weird bug in that the exiting no longer worked as-is,
instead it raised some SystemExit exception.
This confused me a lot because that should not happen at all ever.
Then I realized that the faulty code part was in at_exit (that ruby file
was doing something odd, probably at_exit was not needed either, but
still)
It kind of taught me to be wary with at_exit.
Am I correct in that at_exit may be potentially harmful in a very large
ruby project, when multiple at_exits are doing different things?
Then suddenly one day, I required some files, one of which used at_exit,
and I had a weird bug in that the exiting no longer worked as-is,
instead it raised some SystemExit exception.
This confused me a lot because that should not happen at all ever.
I am writing on a pseudo-ruby shell (with a bash-like syntax).
I usually use ‘q’ to quit it.
Then suddenly one day, I required some files, one of which used at_exit,
and I had a weird bug in that the exiting no longer worked as-is,
instead it raised some SystemExit exception.
This confused me a lot because that should not happen at all ever.
If you want your code to terminate without calling any at_exit handlers
you’ve pulled in,
use “exit!”