I am analyzing the response code from an HTTP Request, and based on that response code, determining how I’m logging that information. The problem is that the data is always being logged as true. For instance, when I get an 500 response code, I want to document a failure. When I get a 200, I want a success. However, I’m always getting a success. Can someone please take a look at my code and either tell me what I’m doing wrong, or what I can do to fix it?
Here is the code giving me a problem:
if response.code == "200" or "201" or "202" or "203" or "204"
I have considered that I am passing in a string, and so when Ruby evaluates the condition, it returns true, but I tried adding: .to_i(base=10) with no success.
Any help would be greatly appreciated.
As already mentioned, its the if statement:
if response.code == "200" or "201" or "202" or "203" or "204"An elegant fix would be: