Today I Learned

hashrocket A Hashrocket project

Ruby's Kernel::abort

Today I used Ruby's Kernel::abort for the first time. It's one of those incredibly useful methods I can't believe I've never seen before.


# abort.rb                                                                                                                                                    {1}
def no_message

def message
  abort('Process terminated')
$ irb
2.2.2 :001 > require './abort'
 => true
2.2.2 :002 > no_message
$ irb                                 {1}
2.2.2 :001 > require './abort'
 => true
2.2.2 :002 > message
Process terminated

Use it to bail from a script.

See More #ruby TILs
Looking for help? Each developer at Hashrocket has years of experience working with Ruby applications of all types and sizes. We're an active presence at Ruby conferences, have written some of the most popular gems, and have worked on many of the web's Ruby on Rails success stories. Contact us today to talk about your Ruby project.