Skip to content

Instantly share code, notes, and snippets.

@inf0rmer
Created December 30, 2014 16:53
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 inf0rmer/147dd9d5c52f2ed77aae to your computer and use it in GitHub Desktop.
Save inf0rmer/147dd9d5c52f2ed77aae to your computer and use it in GitHub Desktop.
Automatically generating ~60 Blanket::Exception subclasses
STATUSES.each_pair do |code, message|
klass = Class.new(Exception) do
send(:define_method, :message) {"#{code ? "#{code} " : ''}#{message}"}
end
klass_constant = const_set message.delete(' \-\''), klass
Exceptions::EXCEPTIONS_MAP[code] = klass_constant
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment