ruby - How to split up an array into a multi-dimensional array -


i have 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 convert 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 |file|   file.split(",") end 

but returns original array. appreciated!

you should use enumerable#map, because enumerable#each iterate through items, #map create new array return value of block:

parsed_data.map { |data| data.split(',') } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -