Ruby 1.9.2 export a CSV string without generating a file

Viewed 6520

I just can't get the 'To a String' example under 'Writing' example in the documentation to work at all.

ruby -v returns: ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0]

The example from the documentation I can't working is here:

csv_string = CSV.generate do |csv|
    csv << ["row", "of", "CSV", "data"]
    csv << ["another", "row"]
end

The error I get is:

wrong number of arguments (0 for 1)

So it seems like I am missing an argument, in the documentation here it states:

This method wraps a String you provide, or an empty default String

But when I pass in a empty string, it gives me the following error:

No such file or directory - 

I am not looking to generate a csv file, I just wanted to create a string of csv that I send as text to the user.

1 Answers
Related