Stop execution of Ruby script

Ruby

Ruby Problem Overview


Is there a method like exit or die in PHP which stops the execution of a Ruby script?

Ruby Solutions


Solution 1 - Ruby

Either abort or exit will help.

Solution 2 - Ruby

abort is an alias for Kernel.exit(false) which terminates execution immediately.

exit is an alias for Kernel.exit(true) and raises the SystemExit exception, that may be caught. Also at_exit functions and finalizers are run before termination.

Solution 3 - Ruby

abort can still hang if there's threads that are waiting. If you really want to terminate immediately try:

Process.kill 9, Process.pid

Solution 4 - Ruby

FYI for ruby on rails, you can simply use this gem shutup, in the rails directory run this command in the bash terminal

gem install shutup

it will find the PID of rails server and kill it.

and also you can do it with lsof -wi tcp:3000 in case you didnt start the server on another port otherwise you should change the port 3000

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionadaxaView Question on Stackoverflow
Solution 1 - RubyIcidView Answer on Stackoverflow
Solution 2 - RubywebwurstView Answer on Stackoverflow
Solution 3 - RubypguardiarioView Answer on Stackoverflow
Solution 4 - Rubym1 e1r0rView Answer on Stackoverflow