Skip to content

Instantly share code, notes, and snippets.

@wannabefro
Created November 21, 2013 16:17
Show Gist options
  • Save wannabefro/7584710 to your computer and use it in GitHub Desktop.
Save wannabefro/7584710 to your computer and use it in GitHub Desktop.
writing and reading files with ruby
require 'CSV'
day_cost = {}
CSV.foreach('hello.csv', headers: true) do |row|
day_cost[row[0]] = row[1]
end
def hourly_wage(wage)
wage.tr('$', '').to_f / 10
end
day_cost.each do |key, val|
File.open('report.txt', 'a') do |file|
file.write("On #{key} I spent #{hourly_wage(val)} per hour \n")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment