Ruby

Ruby

Made by DeepSource

Use the more efficient detect method RB-PR1007

Performance
Major

Usages of select.first, select.last, find_all.first, and find_all.last can be changed to use detect instead.

ActiveRecord compatibility: ActiveRecord does not implement a detect method and find has its own meaning.

Bad practice

[].select { |item| true }.first
[].select { |item| true }.last
[].find_all { |item| true }.first
[].find_all { |item| true }.last

Recommended

[].detect { |item| true }
[].reverse.detect { |item| true }