Skip to content

Files

Latest commit

 

History

History
23 lines (15 loc) · 507 Bytes

Style-EachWithObject.md

File metadata and controls

23 lines (15 loc) · 507 Bytes

Pattern: Use of inject/reduce

Issue: -

Description

This rule looks for inject/reduce calls where the passed in object is returned at the end and so could be replaced by each_with_object without the need to return the object at the end.

Examples

# bad
[1, 2].inject({}) { |a, e| a[e] = e; a }

# good
[1, 2].each_with_object({}) { |e, a| a[e] = e }

Further Reading