A recent Rubocop update introduced a new cop โStyle/MapIntoArrayโ which discourages developers from looping over a collection only to populate another collection with some output.
Instead of this approach we should be using array functions like #map, #select, #reject etc.
# โ Violates Rubocop v1.63.0 Style/MapIntoArray
collection_one = []
collection_two.each do |item|
collection_one.push(item + 1)
end
# โ
Complies with Style/MapIntoArray cop
collection_one = collection_two.map do |item|
item + 1
end