If I have an array that looks like this:
['one', { 'two' => 'three' }, 'four']
['one', 'two, 'three', 'four']
.flatten
.flat_map
I think the closest solution you are going to get is something on the lines of:
['one', { 'two' => 'three' }, 'four'].
flat_map {|f| f.respond_to?(:flatten) ? f.flatten : f }
I prefer the #respond_to?
as it's generally better to check if it quacks like a duck, not if it is a duck.