Skip to content

Instantly share code, notes, and snippets.

@nbfritz
Created December 7, 2012 19:30
Show Gist options
  • Select an option

  • Save nbfritz/4235810 to your computer and use it in GitHub Desktop.

Select an option

Save nbfritz/4235810 to your computer and use it in GitHub Desktop.
HTTP Status Message Type lookup using ranges as keys for a hash
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
})
@nbfritz

nbfritz commented Dec 7, 2012

Copy link
Copy Markdown
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment