Skip to content

Instantly share code, notes, and snippets.

@mfilej
Created December 16, 2014 16:29
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 mfilej/24d4128231f6d9d636f8 to your computer and use it in GitHub Desktop.
Save mfilej/24d4128231f6d9d636f8 to your computer and use it in GitHub Desktop.
class ApiError < StandardError
def self.build(status:, message:, key:)
Class.new(self) do
define_method(:status) { status }
define_method(:message) { message }
define_method(:key) { key }
end
end
end
e = ApiError.build(status: 400, message: "X", key: :lol)
e.class
raise e # => errfactory.rb:14:in `<main>': X
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment