require 'fastercsv' class Array def to_csv(options = {}) if all? { |e| e.respond_to?(:to_row) } FasterCSV.generate do |csv| csv << first.export_columns(options[:format]) csv << map { |e| e.to_row(options[:format]) } end else FasterCSV.generate_line(self, options) end end end