From: James Edward Gray II Date: 2007-10-05T05:06:09+09:00 Subject: Re: FasterCSV warning: alreadery initialized constant CSV On Oct 4, 2007, at 2:55 PM, venkat wrote: > James Edward Gray II wrote: >>> /usr/lib/ruby/gems/1.8/gems/fastercsv-1.2.1/lib/faster_csv.rb: >>> 830: warning: already initialized constant CSV >>> >> I would have to see the code to say for sure. My initial thoughts >> are: >> * CSV is loaded in the script when FCSV tries to build its >> compatibility interface >> * FCSV won't build a compatibility interface unless you ask it to >> * That's the only time FCSV ever touches the CSV namespace > > I wrote a class called "CSVImport" using the default CSV class. > Today, I modified it to work with FasterCSV class by changing the > requires as below: > > begin > require 'rubygems' > require 'faster_csv' > FasterCSV.build_csv_interface > rescue > require 'csv' > end > # Rest of the code You have a bug in that. A bare rescue will not catch the LoadError we are interested in this case. Therefore, using just the above code, I don't believe CSV would ever be loaded. But we know it is loaded because… > The above code in a simple test script doesn't generate any > warnings. My script works even with FasterCSV.build_csv_interface > commented out in the above code fragment. Ah, that's a sign of a problem. Without that line FCSV would not touch CSV and thus it wouldn't exist for you to call methods on. My leading guess is that your code is loading CSV with some code you didn't show me. James Edward Gray II