Converting an Array into a CSV file

require 'csv'

timetable = [
  ['Station Rd', '0610'],
  ['Marleybone Rd', '0622'],
  ['Regent Terrace', '0645'],
  ['Baker Street', '0700']
]

CSV.open('timetable.csv', 'w') do |csv|

  csv << ['Name', 'Time arrival']
  timetable.each {|row|  csv.puts row }

end

Output file: timetable.csv

Name,Time arrival
Station Rd,0610
Marleybone Rd,0622
Regent Terrace,0645
Baker Street,0700

Resources