106

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

Timur Shtatland
  • 12,024
  • 2
  • 30
  • 47
adaxa
  • 1,580
  • 2
  • 14
  • 17

4 Answers4

103

Either abort or exit will help.

user513951
  • 12,445
  • 7
  • 65
  • 82
Icid
  • 1,444
  • 1
  • 12
  • 21
  • 4
    Like @webwurst says in the other answer, use abort to specify a failed end to the script, and exit for a successful end. – Jrgns Jul 01 '14 at 06:04
88

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.

user513951
  • 12,445
  • 7
  • 65
  • 82
webwurst
  • 4,830
  • 3
  • 23
  • 32
7

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

Process.kill 9, Process.pid
pguardiario
  • 53,827
  • 19
  • 119
  • 159
0

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

Darun Omar
  • 21
  • 5