Skip to content

Instantly share code, notes, and snippets.

@atiw003
Created August 14, 2010 13:45
Show Gist options
  • Save atiw003/524313 to your computer and use it in GitHub Desktop.
Save atiw003/524313 to your computer and use it in GitHub Desktop.
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