Skip to content

Instantly share code, notes, and snippets.

@sr75
Created August 26, 2011 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sr75/1173384 to your computer and use it in GitHub Desktop.
Save sr75/1173384 to your computer and use it in GitHub Desktop.
csv_to_array
def csv_to_array(file_location)
csv = CSV::parse(File.open(file_location, 'r') {|f| f.read })
fields = csv.shift
csv.collect { |record| Hash[*(0..(fields.length - 1)).collect {|index| [fields[index],record[index].to_s] }.flatten ] }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment