-
Notifications
You must be signed in to change notification settings - Fork 378
Add Hash#key? vs. Hash#keys.include? and Hash#value? vs. Hash#values.include? #154
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
Conversation
|
Thanks for the contribution. But is this something that people do in practice? I don't think I've ever encountered someone calling |
|
Our team is a group of pretty experienced Ruby developers with a strict code review policy, and I noticed both of these patterns appear in our codebases. I suspect we're not alone. I actually made this PR because I caught myself writing |
|
There sure are a lot of ips blocks there. Also, I'm amused that I too am surprised people use |
|
Can you please split that into 2 sections: one for keys and the other for values - IMO it will look much more readable. |
|
@ixti thanks for the suggestion; done. I also added tests for Thoughts? |
|
I recommend avoid having return unless RANGES[key]But it may lead to confusion: data = { :foo => nil, :bar => false, :baz => 1 }
%i[foo bar baz].map { |k| data.key? k } # => [true, true, true]
%i[foo bar baz].map { |k| data[k] ? true : false } # [false, false, true] |
|
And after all |
|
Oof, you're right @ixti—can't believe I missed that |
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.
LGTM!
|
Thank you! |
No description provided.