Skip to content

Instantly share code, notes, and snippets.

@rubysolo
Created March 14, 2012 19:59
Show Gist options
  • Save rubysolo/2039087 to your computer and use it in GitHub Desktop.
Save rubysolo/2039087 to your computer and use it in GitHub Desktop.
headers = []
File.open("/path/to/file.tsv") do |file|
file.each_line do |line|
data = line.split(/\t/)
if headers.empty?
headers = data
else
data = Hash[*headers.zip(data).flatten]
MyModel.create(data)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment