Skip to content

Instantly share code, notes, and snippets.

@asterite
Last active October 10, 2015 14:16
Show Gist options
  • Save asterite/9d3041b35c4d1b1b9d2e to your computer and use it in GitHub Desktop.
Save asterite/9d3041b35c4d1b1b9d2e to your computer and use it in GitHub Desktop.
AI Anguilla
AL Albania
AM Armenia
require "csv"
filename = ARGV[0]
# This reads the CSV and prints a Hash literal to the output
puts "{"
CSV.each_row(File.read(filename)) do |row|
print row[0].inspect
print " =>"
print row[1].inspect
puts ","
end
puts "}"
# This runs the load_countries program at compile time with "countries.csv"
# as an argument. The result of that execution is a hash literal:
# we paste it in the program (with {{ ... }})
countries = {{ run("./load_countries", "./countries.csv") }}
p countries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment