On Jan 16, 2008, at 3:01 PM, Joel VanderWerf wrote: > ara.t.howard wrote: >> just a quick note, if you ever load a lib with a screwy at_exit >> handler you can monkey patch it by >> require 'spec' >> at_exit{ exit! } # discard *all* pervious exit handlers >> sometimes handy - and dangerous... > > Hm, what about this? > > at_exit do > puts "foo" > end > at_exit do > puts "bar" > end > at_exit do > puts "baz" > end > > # end of existing code, > # monkey patch begins below... > > BEGIN { > def at_exit(&block) > if $at_exit_handlers # or make this local to BEGIN and use > define_method > $at_exit_handlers << block > else > $at_exit_handlers = [block] > super do > while block = $at_exit_handlers.pop > block[$at_exit_handlers] > end > end > end > end > } > > at_exit do |remaining| > remaining.delete_if do |block| > eval("__LINE__", block) == 1 # or use __FILE__ > end > puts "deleted foo handler" > end > > __END__ > > Output: > > deleted foo handler > baz > bar > > -- > vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407 > yeah - something like require 'at_exit_stack' would be a cool gem for sure! a @ http://codeforpeople.com/ -- share your knowledge. it's a way to achieve immortality. h.h. the 14th dalai lama