Skip to content

Instantly share code, notes, and snippets.

@toddsiegel
Created January 4, 2022 23:18
Show Gist options
  • Save toddsiegel/0de3bd7a241101af12d918f63053809c to your computer and use it in GitHub Desktop.
Save toddsiegel/0de3bd7a241101af12d918f63053809c to your computer and use it in GitHub Desktop.
Ruby Cookbook

CSVs

Generate a CSV

csv = CSV.generate(headers: true, force_quotes: true) do |row|
  row << ['ID', 'Name',  'Email']
  people.each do |person|
    row << [person.id, person.name, person.email]
  end
end
csv = "#{csv}" # Add BOM if people are going open this in Excel

File I/O

Write a string to a file

File.write('my_file.txt', 'Hello there!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment