ruby - csv 读写文件 csv read write file --从本地

 def save_to_csv(csv)
    CSV.open("C:/ruby/logs.csv", "w") do |row|
      row << %w[name location dishes time]
    end
  end
  
  def self.read_from_csv(csv)
     CSV.foreach("C:/ruby/logs.csv") do |row|
     puts row ['name', 'location', 'dishes', 'time']
   end
 end

你可能感兴趣的:(ruby)