Check Ruby HTTP response for success

Viewed 44126

How does one properly check the response from Net::HTTP::Get (for example) for "success" (i.e., a 2xx return code)? The documentation seems to be sadly silent on this simple question.

I have:

response=Net::HTTP.new( host, port ).request my_get_request # details not important

After a bunch of Googling and near-random typing, I finally determined that this works:

response.class < Net::HTTPSuccess

Is that actually the canonical way to do it?

3 Answers
Related