Closed koic closed 2 years ago
This PR adds Enumerize::Attribute#value? method.
Enumerize::Attribute#value?
This new method prevents the following breakage when autocorrecting with Performance/InefficientHashSearch cop.
Performance/InefficientHashSearch
-enumerize_attr.values.include?('attr') +enumerize_attr.value?('attr') #=> ArgumentError: wrong number of arguments (given 2, expected 1)
The intention is to add a compatible API for the above, as it does not actually improve performance.
And this method is also used in Enumerize::Predicates#predicate_method?, so the enumerize's test also calls it.
Enumerize::Predicates#predicate_method?
About Performance/InefficientHashSearch cop:
# bad { a: 1, b: 2 }.values.include?('garbage') # good { a: 1, b: 2 }.value?('garbage')
https://docs.rubocop.org/rubocop-performance/1.14/cops_performance.html#performanceinefficienthashsearch
@koic thanks!
This PR adds
Enumerize::Attribute#value?
method.Summary
This new method prevents the following breakage when autocorrecting with
Performance/InefficientHashSearch
cop.The intention is to add a compatible API for the above, as it does not actually improve performance.
And this method is also used in
Enumerize::Predicates#predicate_method?
, so the enumerize's test also calls it.Other Information
About
Performance/InefficientHashSearch
cop:https://docs.rubocop.org/rubocop-performance/1.14/cops_performance.html#performanceinefficienthashsearch