# How can I exit with a message in ruby?

**URL:** <https://www.ruby-forum.com/t/how-can-i-exit-with-a-message-in-ruby/147467>\
**Category:** Ruby\
**Created:** [September 2, 2008, 7:48am UTC](https://www.ruby-forum.com/t/how-can-i-exit-with-a-message-in-ruby/147467 "2008-09-02T07:48:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lpc2148](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de053/32.png) [@lpc2148](https://www.ruby-forum.com/u/lpc2148)\
**Post date:** [September 2, 2008, 7:48am UTC](https://www.ruby-forum.com/t/how-can-i-exit-with-a-message-in-ruby/147467/1 "2008-09-02T07:48:40Z")

</div>

hi guys !

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

---

<div class="post-metadata">

**Author:** ![lpc2148](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de053/32.png) [@lpc2148](https://www.ruby-forum.com/u/lpc2148)\
**Post date:** [September 2, 2008, 8:07am UTC](https://www.ruby-forum.com/t/how-can-i-exit-with-a-message-in-ruby/147467/2 "2008-09-02T08:07:12Z")

</div>

On Tue, Sep 2, 2008 at 7:43 AM, Lex W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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.

---

<div class="post-metadata">

**Author:** ![lpc2148](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de053/32.png) [@lpc2148](https://www.ruby-forum.com/u/lpc2148)\
**Post date:** [September 2, 2008, 8:15am UTC](https://www.ruby-forum.com/t/how-can-i-exit-with-a-message-in-ruby/147467/3 "2008-09-02T08:15:58Z")

</div>

From: “Lex W.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

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

abort “bye…”

Hope this helps,

Bill

---

<div class="post-metadata">

**Author:** ![lpc2148](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de053/32.png) [@lpc2148](https://www.ruby-forum.com/u/lpc2148)\
**Post date:** [September 2, 2008, 9:31am UTC](https://www.ruby-forum.com/t/how-can-i-exit-with-a-message-in-ruby/147467/4 "2008-09-02T09:31:40Z")

</div>

Bill K. wrote:

> From: “Lex W.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
> 
> > does ruby have a die method ? or is it there a method that displays a  
> > string before exiting ?
> 
> abort “bye…”
> 
> Hope this helps,
> 
> Bill

Thanks Bill , just what I was looking for .
