Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the difference between exit and exit! in ruby?

Tags:

What is the difference between exit and exit! in ruby?

like image 333
Prakash Raman Avatar asked Mar 14 '11 06:03

Prakash Raman


People also ask

What does exit do in Ruby?

The exit method simply raises a SystemExit exception. If it's uncaught, the program aborts just like it would with any other uncaught exception.

How do you exit a method in Ruby?

Exiting A Method Ruby methods end naturally on their last line of code. Use the return keyword.

How do you exit Ruby in terminal?

The => symbol lets you know that this is the return value from the Ruby expression. To exit IRB, type exit at the prompt, or press CTRL+D .


1 Answers

Couple things:

  1. Exit handlers get run in the "exit" form but not "exit!". This means any code that is assigned to "clean-up" won't get run using "exit!"

  2. The "exit status" is default set to false in the "exit!" form, whereas it is true in the "exit" form. The "exit status" is a message to the operating system about the program that is stopping execution.

they are both Kernel methods: http://www.ruby-doc.org/core/classes/Kernel.html

like image 128
Brandon Avatar answered Oct 22 '22 17:10

Brandon