0

我有这个数组:

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"]

我想将其转换为:

[["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"]]

我努力了

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

但它返回我的原始数组。任何帮助是极大的赞赏!

4

1 回答 1

5

您应该使用Enumerable#map, 因为Enumerable#each只会遍历项目,但#map会从块的返回值创建一个新数组:

parsed_data.map { |data| data.split(',') }
于 2013-05-10T00:29:27.953 回答