how can I exit with a message in ruby?

L

Lex Williams

hi guys !

does ruby have a die method ? or is it there a method that displays a
string before exiting ?
 
J

Jesús Gabriel y Galán

hi guys !

does ruby have a die method ? or is it there a method that displays a
string before exiting ?

Kernel#at_exit

You can register handlers that get executed when the program exits.

at_exit {puts "Dying"}
puts "In the program"

You can build your own method to print, such as:

module Kernel
def print_at_exit str
at_exit {print str}
end
end

print_at_exit "goodbye"

Jesus.
 
B

Bill Kelly

From: "Lex Williams said:
does ruby have a die method ? or is it there a method that displays a
string before exiting ?

abort "bye..."



Hope this helps,

Bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top