Forum: Ruby Re: How to exit Ruby program properly

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
1c1e3bdfe006a22214102fcd6434a012?d=identicon&s=25 Daniel Sheppard (Guest)
on 2005-12-13 06:03
(Received via mailing list)
Process.exit is the way to go (or just putting the rest of your logic
into the else section of that if statement).

There is nothing unclean about the fact that Process.exit raises an
exception. The fact that it raises an exception is noted to allow other
methods up the chain to intercept and possibly prevent the shutdown.

It also ensures that all the "ensure" thingies up the chain get
executed, so that you file output can be flushed and handles closed and
any other shutdown procedures can come into play. For example:

file = File.new("outfile","w")
begin
	f.puts "Monkeys are cool"
	Process.exit
ensure
	f.close
	puts "File flushed properly"
end

(Note that you'd usually pass a block to File.open, which does the
begin/ensure/close/end bit for you)

If you REALLY want to exit NOW, you can use Process.exit!, but generally
you don't want to do that. Change the above the use Process.exit!, and
you'll notice that "File flushed properly" will not be output - imagine
if there was a more important ensure clause hanging around.


> I'm using Process.exit but the documentation implies that it
> end
>
>
#####################################################################################
This email has been scanned by MailMarshal, an email content filter.
#####################################################################################
This topic is locked and can not be replied to.