I think the problem is twofold:
CSV.dump [a]
wraps an instance of struct a in an array, which then CSV tries to sort. Although this can sometimes be useful when you try to create a CSV file for consumption by some other non-Ruby application that recognizes CSV, you will get values ββthat cannot be used. Looking at the output, this is not a CSV:
class, A
a =, b =
1,2
Look at it in the IRB:
=> "class,A\na=,b=\n1,2\n"
which, again, will not be accepted by something like a spreadsheet or database. So, another tactic is needed.
Removing an array from a does not help:
CSV.dump a => "class,Fixnum\n\n\n\n"
Going off in another way, I looked at the standard way to generate CSV from an array:
puts a.to_a.to_csv => 1,2
An alternative way to create it:
CSV.generate do |csv| csv << a.to_a end => "1,2\n"
source share