Created
December 7, 2012 19:30
-
-
Save nbfritz/4235810 to your computer and use it in GitHub Desktop.
HTTP Status Message Type lookup using ranges as keys for a hash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| STATUS_MESSAGE_TYPES = Hash.new {|h,k| | |
| key = h.keys.find {|e| e.class == Range && e.include?(k) } | |
| key ? h[k] = h[key] : :undefined | |
| }.merge({ | |
| 100..102 => :informational, | |
| 200..208 => :success, | |
| 226 => :success, | |
| 300..308 => :redirection, | |
| 400..417 => :client_error, | |
| 422..431 => :client_error, | |
| 500..511 => :server_error | |
| }) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The neat thing is that when a message type is found by lookup against the ranges, it is then added to the hash to expedite lookups for that same status code in the future.