Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails 3 ruby 1.9.2 CSV "already initialized constant .." warning

I want to add the ability to read/write data to a CSV file to one of my models. In versions of ruby prior to 1.9 this would have been done with fasterCSV, but this is now part of ruby. I have the following setup:

#in my_model.rb
require 'CSV'

class MyModel < ActiveRecord::Base
   ... stuff ...
   def self.dump_to_csv(file=File.join(Rails.root, 'tmp', 'dump', 'my_model.csv'))
      CSV.open(file, "w") do |csv|
         keys = new.attributes.keys
         csv << keys
         all.each do |m|
            csv << m.attributes.values_at(*keys)
         end
      end
    end
end

This works fine, however when I come to run tests I get a load of warnings of the form

/Users/x/.rvm/rubies/ruby-1.9.2-rc2/lib/ruby/1.9.1/csv.rb:201: warning: already initialized constant VERSION
/Users/x/.rvm/rubies/ruby-1.9.2-rc2/lib/ruby/1.9.1/csv.rb:863: warning: already initialized constant FieldInfo
/Users/x/.rvm/rubies/ruby-1.9.2-rc2/lib/ruby/1.9.1/csv.rb:866: warning: already initialized constant DateMatcher
... 

How can I remove these warnings?

like image 256
Tom Close Avatar asked Feb 24 '23 07:02

Tom Close


1 Answers

I ran into the same issue, after some digging I realized that I was requiring 'CSV' where I should have been requiring 'csv' it should be all lowercase.

like image 191
Claude Avatar answered Feb 26 '23 20:02

Claude