Catching script end?

All,

Are you aware of anyway to catch the end of a Ruby script execution when
there is no explicit exit instruction?

a) SystemExit seems to be raised only when ‘exit’ is used explicitely.
b) I have found a workaround to catch exit! as well by redefining

But what to do when there is no exit at all ?

Thanks for your help

Laurent

Are you aware of anyway to catch the end of a Ruby script execution when
there is no explicit exit instruction?

Something like this ?

pigeon% ruby -e 'at_exit { p "end" }'
"end"
pigeon%

Guy Decoux

Laurent Julliard Laurent.Julliard@xrce.xerox.com wrote in message news:3D53EC0C.5060405@xrce.xerox.com

All,

Are you aware of anyway to catch the end of a Ruby script execution when
there is no explicit exit instruction?

a) SystemExit seems to be raised only when ‘exit’ is used explicitely.
b) I have found a workaround to catch exit! as well by redefining

But what to do when there is no exit at all ?

Thanks for your help

Laurent

How about using an END block?

In this example, I use an END block and its complementarhy BEGIN block:

BEGIN {
puts ‘Welcome’
}

puts ‘hello, world’

END {
puts ‘Goodbye, cruel world.’
}

gives:

Welcome
hello, world
Goodbye, cruel world.

ts wrote:

“L” == Laurent Julliard Laurent.Julliard@xrce.xerox.com writes:

Are you aware of anyway to catch the end of a Ruby script execution when
there is no explicit exit instruction?

Something like this ?

pigeon% ruby -e ‘at_exit { p “end” }’
“end”
pigeon%

at_exit is exactly what I was looking for. I combined this with aliasing
exit! to exit (at_exit doesn’t catch exit!) in my ruby module and now I
catch all exit events whether they come from and explicit exit/exit! or
from an implicit exit

Thanks for the tip!

Laurent