Created
November 21, 2013 16:17
-
-
Save wannabefro/7584710 to your computer and use it in GitHub Desktop.
writing and reading files with ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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