Reputation: 111
How can I convert ["90 99 8 9 11 22"] to ["90", "99", "8", "9", "11", "22"] in Ruby ?
["90 99 8 9 11 22"]
["90", "99", "8", "9", "11", "22"]
Upvotes: 1
Views: 38
Reputation: 3201
With flat_map and split it works with any number of items:
flat_map
split
["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"]
Upvotes: 3