Skip to content

Instantly share code, notes, and snippets.

@ryanjm ryanjm/small.csv

Created Jun 29, 2012
What would you like to do?
# opens file
f ='small.csv','r')
# grab all the lines (array)
lines = f.readlines
# header will be first line, take it out and strip white space
headers = lines.shift.strip
keys = headers.split(',')
# value to hold presidents
presidents = []
# loop over remaining lines
lines.each do |line|
values = line.strip.split(',')
params = {}
keys.each_with_index do |key,i|
params[key] = values[i]
presidents << params
puts "Presidents:"
puts presidents
Presidency President
1 George Washington
2 John Adams
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.