New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support of String#to_boolean #9667
Conversation
# "0".to_boolean #=> false | ||
# "foo".to_boolean #=> ArgumentError: invalid boolean | ||
def to_boolean | ||
return true if %w(true t 1).include?(self.downcase) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's a good idea to use a regexp for that purpose as it's time-consuming and it should be processed twice (true and false).
include?
better fits this needs IMO
Can you demonstrate a real-world use case of this making code cleaner? We don't add extensions to String unless it's really important. |
👎 |
|
That's an issue of accept nested attributes for. Maybe it should yield this In any case, -1 for this PR, even more because its implementation is very José Valim |
It would seem to be overkill to extend a Ruby core class to make the code in this one very particular use case a little terser. How about a helper function in |
I agree with @josevalim. Closing. Thank you for the pull request. |
Thanks for reviewing and your fast feedbacks :-) |
This is a nice utility function to have when importing other people's data. Was expecting ActiveSupport would have something like it. |
No description provided.