Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save j4zzcat/d6c62563dda34f749c7f22aee97892a3 to your computer and use it in GitHub Desktop.
Save j4zzcat/d6c62563dda34f749c7f22aee97892a3 to your computer and use it in GitHub Desktop.
file utils.rb:
--------------
require 'webrick'
module Utils
WEBrick::HTTPStatus::StatusMessage.each do | k, v |
self.const_set "HTTP_#{k}_#{v.upcase.tr ' -', '_'}".to_sym, k
end
end
file app.rb:
------------
require 'utils'
puts Utils::HTTP_200_OK. # => 200
puts Utils::HTTP_201_CREATED # => 201
# etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment