Edited at

[Ruby] HTTP ステータスコードを扱うのに WEBrick::HTTPStatus が便利


WEBrick::HTTPStatus

WEBrick::HTTPStatus は標準添付ライブラリなので Gem なしで使えて便利 :blush:

WEBrick::HTTPStatus.info?(101)

#=> true
WEBrick::HTTPStatus.reason_phrase(101)
#=> "Switching Protocols"

WEBrick::HTTPStatus.success?(200)
#=> true
WEBrick::HTTPStatus.reason_phrase(200)
#=> "OK"

WEBrick::HTTPStatus.redirect?(301)
#=> true
WEBrick::HTTPStatus.reason_phrase(301)
#=> "Moved Permanently"

WEBrick::HTTPStatus.client_error?(403)
#=> true
WEBrick::HTTPStatus.reason_phrase(403)
#=> "Forbidden"

WEBrick::HTTPStatus.server_error?(500)
#=> true
WEBrick::HTTPStatus.reason_phrase(500)
#=> "Internal Server Error"


参考