What is the difference between exit and exit! 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.
Exiting A Method Ruby methods end naturally on their last line of code. Use the return keyword.
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 .
Couple things:
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!"
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With