Pattern: Missing use of map
Issue: -
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.
# 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