I am trying to use FasterCSV and am getting an error.
I installed the fastercsv gem and it appeared to install correctly.
This is the error that I’m getting:
…/fastercsv.rb:3: uninitialized constant FasterCSV (NameError)
from C:/Program
Files/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in gem_original_require' from C:/Program Files/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:inrequire’
from fastercsv.rb:1
Here’s the code:
require ‘rubygems’
require ‘fastercsv’
FasterCSV.foreach(“data.csv”) do |person|
puts person.inspect
end
It seems pretty simple – it’s just some code that I got out of a book
– so I’m surprised that I’m getting that error. It seems to me that
the error might indicate that the gem didn’t actually install properly.
If anyone has any insight into this, I’d appreciate it.
I am trying to use FasterCSV and am getting an error.
Sorry to hear that. I’ll try to provide some guesses…
I installed the fastercsv gem and it appeared to install correctly.
This is the error that I’m getting:
…/fastercsv.rb:3: uninitialized constant FasterCSV (NameError)
from C:/Program Files/Ruby/lib/ruby/site_ruby/1.8/rubygems/
custom_require.rb:27:in gem_original_require' from C:/Program Files/Ruby/lib/ruby/site_ruby/1.8/rubygems/ custom_require.rb:27:inrequire’
from fastercsv.rb:1
That error is a little strange because it is complaining about a lack
of a FasterCSV constant in the require. The file you required though,
fastercsv.rb, does not have a FasterCSV constant anywhere in it.
(It’s a shim that loads some other code.)
My guess is this: you named your own file fastercsv.rb. When you try
to require the gem, Ruby is finding your file first and it fails to
load because FasterCSV was never defined. If I’m right, you just need
to rename your file and it will work.
My guess is this: you named your own file fastercsv.rb. When you try
to require the gem, Ruby is finding your file first and it fails to
load because FasterCSV was never defined. If I’m right, you just need
to rename your file and it will work.
That was an awesome piece of deduction, and a joy to see.
On Mon, 2008-03-17 at 00:50 +0900, James G. wrote:
to require the gem, Ruby is finding your file first and it fails to
load because FasterCSV was never defined. If I’m right, you just
need
to rename your file and it will work.
That was an awesome piece of deduction, and a joy to see.
I got lucky.
I’ve seen this problem come up before, a couple of times - hell, I’ve
even made the same mistake myself more than once
Is there a decent use case for require() loading the same file it was
called from, or is it allowed because preventing it (or treating the
file itself as effectively at the tail end of $:) would require too much
overhead?