Skip to content

Instantly share code, notes, and snippets.

@blairanderson
Created December 21, 2017 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blairanderson/2d2e3903cfa84b8f1c929fea7568f2d8 to your computer and use it in GitHub Desktop.
Save blairanderson/2d2e3903cfa84b8f1c929fea7568f2d8 to your computer and use it in GitHub Desktop.
Ruby Argument Error with Custom Message

If you want to raise an argument error with a clearer message

def process_thing(account: nil, thing: nil)
  raise(ArgumentError.new("processing requires an account")) if account.blank?
  raise(ArgumentError.new("Must have a Thing to process")) if thing.blank?
  # ... Do the actual work
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment