[Solved] Ruby CSV.readline convert to hash

[ad_1]

matches = []

File.readlines('data.txt').each do |line|

  my_line = line.chomp.split(', ').map! { |l| l.split(/\s+(?=\d+$)/) }.flatten 

  matches << [['player1', 'scope_p1', 'player2', 'score_p2'], my_line].transpose.to_h

end

p matches

Example Here

3

[ad_2]

solved Ruby CSV.readline convert to hash