# How can I exit with a message in ruby?

**URL:** <https://rubytalk.org/t/how-can-i-exit-with-a-message-in-ruby/48799>\
**Category:** ruby-talk\
**Created:** [2 September 2008 05:43 UTC](https://rubytalk.org/t/how-can-i-exit-with-a-message-in-ruby/48799 "2008-09-02T05:43:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lex\_Williams](https://avatars.discourse-cdn.com/v4/letter/l/e5b9ba/32.png) [@Lex\_Williams](https://rubytalk.org/u/Lex_Williams)\
**Post date:** [2 September 2008 05:43 UTC](https://rubytalk.org/t/how-can-i-exit-with-a-message-in-ruby/48799/1 "2008-09-02T05:43:19Z")

</div>

hi guys !

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

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Jesus\_Gabriel\_y\_Gala](https://avatars.discourse-cdn.com/v4/letter/j/96bed5/32.png) [@Jesus\_Gabriel\_y\_Gala](https://rubytalk.org/u/Jesus_Gabriel_y_Gala)\
**Post date:** [2 September 2008 06:00 UTC](https://rubytalk.org/t/how-can-i-exit-with-a-message-in-ruby/48799/2 "2008-09-02T06:00:26Z")

</div>

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  
&nbsp;&nbsp;&nbsp;at\_exit {print str}  
end  
end

print\_at\_exit "goodbye"

Jesus.

> **···**
>
> On Tue, Sep 2, 2008 at 7:43 AM, Lex Williams \<etaern@yahoo.com\> wrote:
> 
> > 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:** ![Bill\_Kelly](https://avatars.discourse-cdn.com/v4/letter/b/cc9497/32.png) [@Bill\_Kelly](https://rubytalk.org/u/Bill_Kelly)\
**Post date:** [2 September 2008 06:09 UTC](https://rubytalk.org/t/how-can-i-exit-with-a-message-in-ruby/48799/3 "2008-09-02T06:09:51Z")

</div>

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

abort "bye..."

Hope this helps,

Bill

> **···**
>
> From: "Lex Williams" \<etaern@yahoo.com\>

---

<div class="post-metadata">

**Author:** ![Lex\_Williams](https://avatars.discourse-cdn.com/v4/letter/l/e5b9ba/32.png) [@Lex\_Williams](https://rubytalk.org/u/Lex_Williams)\
**Post date:** [2 September 2008 07:26 UTC](https://rubytalk.org/t/how-can-i-exit-with-a-message-in-ruby/48799/4 "2008-09-02T07:26:22Z")

</div>

Bill Kelly wrote:

> From: "Lex Williams" \<etaern@yahoo.com\>
> 
> > 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 .

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
