How can I convert ["90 99 8 9 11 22"] to ["90", "99", "8", "9", "11", "22"] in Ruby ?
CodePudding user response:
With flat_map and split it works with any number of items:
["90 99 8 9 11 22"].flat_map(&:split)
=> ["90", "99", "8", "9", "11", "22"]
> ["90 99 8 9 11 22", "1 2 3"].flat_map(&:split)
=> ["90", "99", "8", "9", "11", "22", "1", "2", "3"]
