Skip to content

CAT 002

unurgunite edited this page Jul 11, 2026 · 3 revisions

CAT-002 — map{}.sum → sum{}

Severity: warningConfidence: highAuto-fix:

Tip

This rule supports auto-fix via --fix

Description

map{}.sum → sum{} — Use sum with a block instead of map + sum to avoid creating an intermediate array.

Bad code

ary.map { |x| x * 2 }.sum

Good code

ary.sum { |x| x * 2 }

Performance Impact

Tip

This rule can significantly improve performance in hot code paths.

Benchmark

Note

See bench results at bench/cat-002/

Clone this wiki locally