I would like to know if there is a method in Ruby that splits an Array of String in smallest pieces. Consider:
['Cheese crayon', 'horse', 'elephant a b c']
Is there a method that turns this into:
['Cheese', 'crayon', 'horse', 'elephant', 'a', 'b', 'c']
p ['Cheese crayon', 'horse', 'elephant a b c'].flat_map(&:split)
# => ["Cheese", "crayon", "horse", "elephant", "a", "b", "c"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With