Today's Question:  What's your opinion about Alibaba mooncake incident?        GIVE A SHOUT

  WRITE ARTICLE

 ALL


  Gracefully exiting from console programs in Ruby

Imagine you write a CLI program or a Rake task which loops through some data performing some work on it. You run it and then you remembered something. You’d love to kill the process with ctrl-c, but that will raise an exception somewhere in the loop. What you want is for the iteration to complete and then you want the program to quit. You could handle the Interrupt exception or add some conditions. But how about a cleaner and reusable way? No problem - you can trap signals, which mean...

2,208 0 0          RUBY CONSOLE EXIT COMMAND WINDOW GRACEFUL