Error using FasterCSV

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: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.

Thanks,

Glenn

On Mar 15, 2008, at 7:29 AM, Glenn wrote:

Hi,

Hello.

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.

Hope that helps.

James Edward G. II

Hey,

On Sun, Mar 16, 2008 at 1:35 AM, James G. [email protected]
wrote:

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 G. II

Cheers!
Arlen

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. :wink:
I’ve seen this problem come up before, a couple of times - hell, I’ve
even made the same mistake myself more than once :slight_smile:

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?

On Mar 16, 2008, at 6:39 AM, Arlen C. wrote:

need
to rename your file and it will work.

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

I got lucky. :wink:

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 G. II

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs