Migrating FasterCSV from ruby 1.8 to CSV in 1.9+
Currently in StreetEasy we're moving a Rails app from Ruby 1.8 to 1.9
In Ruby 1.9 FasterCSV is already included as standard library's CSV. And in Ruby 1.9 you can't continue using FasterCSV, if you do, you'll get an error message like this:
Please switch to Ruby 1.9's standard CSV library. It's FasterCSV plus support for Ruby 1.9's m17n encoding engine.
The workaround for this is, instruct bundler to include fastercsv only if I'm running ruby 1.8:
gem 'fastercsv', :platforms => :ruby_18
And change references in the application from FasterCSV to CSV, and add this (in a Rails app usually in the config/environment.rb):
require 'csv' if CSV.const_defined? :Reader # Ruby 1.8 compatible require 'fastercsv' Object.send(:remove_const, :CSV) CSV = FasterCSV else # CSV is now FasterCSV in ruby 1.9 end
Based on a James Edward Gray II post