You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This made me think about the readability and expressiveness of the code. The standard approach, res.code == 401, gets the job done, but I wondered if we could introduce helper methods like _401? to make this even clearer.
With the proposed change, the above example could look like this:
I understand that in Ruby, methods can't begin with a number, so I've prefixed it with an underscore. I know this might not be everyone's favorite syntax, so I'm very open to feedback or alternative naming suggestions.
Why is this beneficial?
Readability: The code's intent becomes very clear.
Expressiveness: It aligns with the Ruby idiom of providing ? methods for conditions.
Convenience: Especially when dealing with multiple status checks, this can make the code look cleaner.
Would love to hear your thoughts on this. If it's something the community feels is valuable, I'd be willing to look into helping with implementation. Otherwise, if it's deemed not to fit the direction or philosophy of the library, no worries at all.
The text was updated successfully, but these errors were encountered:
I'm on the fence for helper methods. I like them but it also could collide with the underlying response that is being delegated to normally. I don't like underscore prefixed, but the methods from that gist seem do-able. Not sure how often most of them would get used as I assume people wouldn't remember what method name matches to what status code.
While working on a project, I often encountered scenarios where I was checking the response code to handle specific HTTP status codes. For instance:
This made me think about the readability and expressiveness of the code. The standard approach,
res.code == 401
, gets the job done, but I wondered if we could introduce helper methods like_401?
to make this even clearer.With the proposed change, the above example could look like this:
I understand that in Ruby, methods can't begin with a number, so I've prefixed it with an underscore. I know this might not be everyone's favorite syntax, so I'm very open to feedback or alternative naming suggestions.
Why is this beneficial?
Would love to hear your thoughts on this. If it's something the community feels is valuable, I'd be willing to look into helping with implementation. Otherwise, if it's deemed not to fit the direction or philosophy of the library, no worries at all.
The text was updated successfully, but these errors were encountered: