Skip to content

Files

Latest commit

 

History

History
30 lines (20 loc) · 602 Bytes

Style-MapIntoArray.md

File metadata and controls

30 lines (20 loc) · 602 Bytes

Pattern: Missing use of map

Issue: -

Description

Checks for usages of each with <<, push, or append which can be replaced by map.

If PreferredMethods is configured for map in Style/CollectionMethods, this cop uses the specified method for replacement.

Examples

# bad
dest = []
src.each { |e| dest << e * 2 }
dest

# good
dest = src.map { |e| e * 2 }

# good - contains another operation
dest = []
src.each { |e| dest << e * 2; puts e }
dest

Further Reading