I have noticed a common pattern in my Ruby projects. Here is an example.
def collect_reverses b
a = []
b.each do |element|
a << element.reverse
end
a
end
This particular example is stripped down to the bare essentials. Usually the code inside of the loop is more complicated.
The pattern described works. However, the procedural nature of this pattern is in stark contrast with the object oriented nature of the rest of the code.
Is there a cleaner/more OO method to accomplish the same task?
See
Enumerable#collect(also known asmap):