Nov 12
Ruby 1.9 CSV undefined method map for String
I’m in the process of upgrading an app running Ruby EE 1.8.7 to Ruby 1.9.2. Since FasterCSV is no longer available, I had to convert the code to use the internal CSV lib. In doing so, I ran into the above error. Looking at the source for FasterCSV <<, there was a catchall else statement that would handle passing a string and convert it to an array to become a row.
def <<(arg) if arg.is_a?(Array) and arg.size == 2 # appending a header and name @row << arg elsif arg.is_a?(Hash) # append header and name pairs arg.each { |pair| @row << pair } else # append field value @row << [nil, arg] end self # for chaining end
In Ruby 1.9 the CSV << method is expecting an Array or CSV::Row. Easiest fix for me as to just make my string an Array. Hope this helps!
1 comment1 Comment so far
Leave a comment
Thank you! I’d been searching for the longest time and this solved my problem!