我有这个数组:
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
但它返回我的原始数组。非常感谢任何帮助!
答案 0 :(得分:5)
您应该使用Enumerable#map
,因为Enumerable#each
只会遍历项目,但#map
会根据块的返回值创建一个新数组:
parsed_data.map { |data| data.split(',') }