Skip to content

Instantly share code, notes, and snippets.

@TwP
Created January 6, 2012 17:16
Show Gist options
  • Save TwP/1571514 to your computer and use it in GitHub Desktop.
Save TwP/1571514 to your computer and use it in GitHub Desktop.
at_exit callback ordering
# The purpose of this experiment is to see if we can force our at_exit handler
# to be the very last one invoked regardless of the order in which the at_exit
# handlers are registered. The Ruby documentation states that the at_exit
# handlers are called in the reverse order in which they are registered. So
# the first one registered is the last one called.
at_exit { STDOUT.puts "first" }
at_exit {
STDOUT.puts "second"
at_exit { STDOUT.puts "LAST ONE!!" }
}
at_exit { STDOUT.puts "thrid" }
STDOUT.puts "exiting"
=begin ---- output ----
exiting
thrid
second
first
LAST ONE!!
=end
@judofyr
Copy link

judofyr commented Jan 6, 2012

There are some issues about this on Redmine. I think it changed in 1.9.3 (or maybe 1.9.2).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment