<p>Is there a one line function call that quits the program and displays a message? I know in Perl it's as simple as:</p>

<pre><code>die("Message goes here")
</code></pre>

<p>I'm tired of typing this:</p>

<pre><code>puts "Message goes here"
exit
</code></pre>

[{'answer_id': 29547, 'author': 'Mike Stone', 'author_id': 122, 'author_profile': 'https://Stackoverflow.com/users/122', 'pm_score': 1, 'selected': False, 'text': "<p>I've never heard of such a function, but it would be trivial enough to implement...</p>\n\n<pre><code>def die(msg)\n  puts msg\n  exit\nend\n</code></pre>\n\n<p>Then, if this is defined in some .rb file that you include in all your scripts, you are golden.... just because it's not built in doesn't mean you can't do it yourself ;-)</p>\n"}, {'answer_id': 29587, 'author': 'Jörg W Mittag', 'author_id': 2988, 'author_profile': 'https://Stackoverflow.com/users/2988', 'pm_score': 5, 'selected': False, 'text': "<p>If you want to denote an actual error in your code, you could raise a <code>RuntimeError</code> exception:</p>\n\n<pre><code>raise RuntimeError, 'Message goes here'\n</code></pre>\n\n<p>This will print a stacktrace, the type of the exception being raised and the message that you provided. Depending on your users, a stacktrace might be too scary, and the actual message might get lost in the noise. On the other hand, if you die because of an actual error, a stacktrace will give you additional information for debugging.</p>\n"}, {'answer_id': 86325, 'author': 'Chris Bunch', 'author_id': 422, 'author_profile': 'https://Stackoverflow.com/users/422', 'pm_score': 10, 'selected': True, 'text': '<p>The <code>abort</code> function does this. For example:</p>\n\n<pre><code>abort("Message goes here")\n</code></pre>\n\n<p>Note: the <code>abort</code> message will be written to <code>STDERR</code> as opposed to <code>puts</code> which will write to <code>STDOUT</code>.</p>\n'}, {'answer_id': 43490860, 'author': 'Giuse', 'author_id': 6392246, 'author_profile': 'https://Stackoverflow.com/users/6392246', 'pm_score': 2, 'selected': False, 'text': '<p>I got here searching for a way to execute some code whenever the program ends.<br>\n<a href="https://ruby-doc.org/core-2.4.1/Kernel.html#method-i-at_exit" rel="nofollow noreferrer" title="Kernel.at_exit">Found this</a>:</p>\n\n<pre><code>Kernel.at_exit { puts "sayonara" }\n# do whatever\n# [...]\n# call #exit or #abort or just let the program end\n# calling #exit! will skip the call\n</code></pre>\n\n<p>Called multiple times will register multiple handlers.</p>\n'}]
['https://Stackoverflow.com/questions/29539', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/422/']