0

I have this array:

parsed_data = ["Mike Henry,7/7/87,Oakland,831 123-2758", "David Jordan,12/30/92,Bangkok,831 229-1234", "Matt Rosen,5/21/89,Seattle,925 518-9933"]

I would like to convert it to:

[["Mike Henry", "7/7/87", "Oakland", "831 123-2758"],["David Jordan", "12/30/92", "Bangkok", "831 229-1234"],["Matt Rosen", "5/21/89", "Seattle", "925 518-9933"]]

I have tried

parsed_data = parsed_data.each do |file|
  file.split(",")
end

but it returns my original array. Any help is greatly appreciated!

emailnitram
  • 141
  • 2
  • 12
  • Might be a duplicate depending upon your interpretation: http://stackoverflow.com/questions/5254128/arrayeach-vs-arraymap – squiguy May 10 '13 at 00:34

1 Answers1

5

You should use Enumerable#map, because Enumerable#each will just iterate through the items, but #map will create a new array from the return value of the block:

parsed_data.map { |data| data.split(',') }
KARASZI István
  • 30,900
  • 8
  • 101
  • 128