Add Hash#key? vs. Hash#keys.include? and Hash#value? vs. Hash#values.include? - #154
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 |
|
Thank you! |
No description provided.