Home > ruby > Kill Messages on Ruby applications

Kill Messages on Ruby applications

Trying to get into ruby and i ran in to a somewhat important requirement. I need to know when my app is closing, wether it was me that shut it down or the OS just simply sent it a kill message. So i did some digging, made a fool of my self by posting to comp.lang.ruby and later on found the solution. Directly from the ruby documentation:

at_exit { block } → proc

Converts block to a Proc object (and therefore binds it at the point of call) and registers it for execution when the program exits. If multiple handlers are registered, they are executed in reverse order of registration.

   def do_at_exit(str1)
     at_exit { print str1 }
   end
   at_exit { puts "cruel world" }
   do_at_exit("goodbye ")
   exit

produces:

   goodbye cruel world

For more info visit here

Advertisements
Categories: ruby Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: