Skip to content

Latest commit

 

History

History
24 lines (18 loc) · 456 Bytes

fail.md

File metadata and controls

24 lines (18 loc) · 456 Bytes

Fail

The fail method is synonymous with raise in Ruby. Consider the following code snippet:

def is_odd?(num)
  num.odd?
rescue
  fail StandardError, 'you cannot use odd on this'
end

> is_odd?(1)
#=> true
> is_odd?('hello')
#=> StandardError: you cannot use odd on this

Nevertheless, I believe the raise method is preferred to the fail method.

source

h/t Dorian Karter