Create array from some string from text file – Ruby

I’m trying to create array from string from text file.

For example in txt file I have string.


I want to create array which looks like:


I have tried that using method below: { |line| line.split(/;/) }

but output of the above method was:


You may notice that this is an array within an array.

What I should to do?

>Solution :

Use flat_map instead of map

Code{ |line| line.split(/;/) }

Leave a Reply