Lately I asked on IRC:
- 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?
···
--
Posted via http://www.ruby-forum.com/.
Any and all code is potentially harmful in any size project. I don't see how at_exit is different or special in that aspect in any way.
···
On Jan 12, 2012, at 14:44 , Marc Heiler wrote:
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?
It should happen always, regardless of at_exit:
begin
exit 1
rescue SystemExit => e
p e
end
# => #<SystemExit: exit>
···
On Jan 12, 2012, at 14:44 , Marc Heiler wrote:
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.
Marc Heiler wrote in post #1040604:
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!"
Regards,
Brian.
···
--
Posted via http://www.ruby-forum.com/\.
I wrote a gist not too long ago that seems appropriate here:
···
On Fri, Jan 13, 2012 at 3:09 PM, Ryan Davis <ryand-ruby@zenspider.com> wrote:
On Jan 12, 2012, at 14:44 , Marc Heiler wrote:
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.
It should happen always, regardless of at_exit:
begin
exit 1
rescue SystemExit => e
p e
end
# => #<SystemExit: exit>