I had the following Ruby code:

CSV.generate(force_quotes: true) do |csv|
  csv << headers
  rows.each do |row|
    csv << row
  end
end

Running it unexpectedly led to the following error:

NoMethodError - undefined method ‘collect’ for nil:NilClass:

I had no idea why, but luckily, I came across a Japanese article that helped me resolve it: RubyのCSV作成時に undefined method ‘collect’ for nil:NilClass エラーが出たときの対処.

While two fixes are listed, the first one—changing csv << row to csv << row.values—immediately resolved the issue for me.


<
Previous Post
Cleaning Up Old F#
>
Blog Archive
Archive of all previous blog posts