lib/csv_rails/array.rb in csv_rails-0.4.0 vs lib/csv_rails/array.rb in csv_rails-0.4.1

- old
+ new

@@ -9,21 +9,22 @@ module InstanceMethods def to_csv(opts={}) return "" if length < 1 first = self.first fields = opts.delete(:fields) || first.class.attribute_names - CSV.generate do |csv| + csv = CSV.generate do |_csv| unless opts[:without_header] - csv << if first.class.respond_to?(:human_attribute_name) + _csv << if first.class.respond_to?(:human_attribute_name) fields.map{|f| first.class.human_attribute_name(f) } else fields end end each do |element| - csv << element.to_csv_ary(fields, opts) + _csv << element.to_csv_ary(fields, opts) end end + opts[:encoding] ? csv.encode(opts[:encoding]) : csv end end end end