I know how select, collect and map work in Ruby. I was just wondering if there is a similar native Ruby method that can combine them & give results in a single iteration without having the need to remove nil from array?
For ex.
(1..10).map { |x| x*3 if x.even? }.compact
(1..10).select { |x| x.even? }.map{ |x| x*3 }
(1..10).select { |x| x.even? }.collect{ |x| x*3 }
all give same result, which is [6, 12, 18, 24, 30]. But is there 'some_method' gives the same result?
(1..10).some_method { |x| x*3 if x.even? } ## evaluates to [6, 12, 18, 24, 30]