Tuesday, August 5, 2008

Catching Ctrl+C in Ruby 1.9

Ctrl+C sends a SIGINT signal to the kernel.
To catch it and execute code we use:
Kernel.trap('INT') { code }
Remember to call Kernel.exit if you want to terminate the execution of your ruby script. Kernel.trap can also catch other signals. For more information visit: Kernel.trap

No comments: