tools/rest_api.rb
Use find
instead of select.first
. Open
Open
gem_dir = Pathname.new(Bundler.locked_gems.specs.select { |g| g.name == "manageiq-api" }.first.gem_dir)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop is used to identify usages of
select.first
, select.last
, find_all.first
, and find_all.last
and change them to use detect
instead.
Example:
# bad
[].select { |item| true }.first
[].select { |item| true }.last
[].find_all { |item| true }.first
[].find_all { |item| true }.last
# good
[].detect { |item| true }
[].reverse.detect { |item| true }
ActiveRecord
compatibility:
ActiveRecord
does not implement a detect
method and find
has its
own meaning. Correcting ActiveRecord methods with this cop should be
considered unsafe.