Skip to content

Latest commit

 

History

History
26 lines (18 loc) · 568 Bytes

Performance-Sum.md

File metadata and controls

26 lines (18 loc) · 568 Bytes

Pattern: Missing use of Enumerable#sum

Issue: -

Description

This rule identifies places where custom code finding the sum of elements in some Enumerable object can be replaced by Enumerable#sum method.

Examples

# bad
[1, 2, 3].inject(:+)
[1, 2, 3].reduce(10, :+)
[1, 2, 3].inject(&:+)
[1, 2, 3].reduce { |acc, elem| acc + elem }

# good
[1, 2, 3].sum
[1, 2, 3].sum(10)
[1, 2, 3].sum

Further Reading