ruby - CSV file to hash -


i want take simple 2-column csv file , turn hash of initials keys, full name values. how this?

csv_text = file.read('composer_initials.csv')  csv = csv.parse(csv_text, :headers => true) 

i've tried:

csv.to_a.map {|row| ro.to_hash} csv.map {|row| row.to_hash} 

solution:

this ended doing job:

composers = {}  csv.foreach("composer_initials.csv") |row|   composers[row[0]] = row[1] end 

hash = {} csv= csv.parse(csv_text) csv.each |row|   hash[row[0]] = row[1] end 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -