blairanderson
12/21/2017 - 10:02 PM

Ruby Argument Error with Custom Message

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