Error using FasterCSV

G

Glenn

[Note: parts of this message were removed to make it a legal post.]

Hi,

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:in `require'
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.

Thanks,

Glenn
 
J

James Gray

Hi,
Hello.

I am trying to use FasterCSV and am getting an error.

Sorry to hear that. I'll try to provide some guesses=85
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/=20
custom_require.rb:27:in `gem_original_require'
from C:/Program Files/Ruby/lib/ruby/site_ruby/1.8/rubygems/=20
custom_require.rb:27:in `require'
from fastercsv.rb:1

That error is a little strange because it is complaining about a lack =20=

of a FasterCSV constant in the require. The file you required though, =20=

fastercsv.rb, does not have a FasterCSV constant anywhere in it. =20
(It's a shim that loads some other code.)

My guess is this: you named your own file fastercsv.rb. When you try =20=

to require the gem, Ruby is finding your file first and it fails to =20
load because FasterCSV was never defined. If I'm right, you just need =20=

to rename your file and it will work.

Hope that helps.

James Edward Gray II=
 
A

Arlen Cuss

[Note: parts of this message were removed to make it a legal post.]

Hey,

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.

James Edward Gray II

Cheers!
Arlen
 
J

James Gray

Hey,



That was an awesome piece of deduction, and a joy to see.

I got lucky. ;)

Besides, the stack trace included a lot of good hints. It gave me
line numbers that matched the code shown, for example.

Anyway, I'm glad we figured it out.

James Edward Gray II
 
A

Alex Young

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,189
Members
46,735
Latest member
HikmatRamazanov

Latest Threads

Top