# Error using FasterCSV

**URL:** <https://www.ruby-forum.com/t/error-using-fastercsv/132018>\
**Category:** Ruby\
**Created:** [March 15, 2008, 1:29pm UTC](https://www.ruby-forum.com/t/error-using-fastercsv/132018 "2008-03-15T13:29:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![glenn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@glenn](https://www.ruby-forum.com/u/glenn)\
**Post date:** [March 15, 2008, 1:29pm UTC](https://www.ruby-forum.com/t/error-using-fastercsv/132018/1 "2008-03-15T13:29:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![glenn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@glenn](https://www.ruby-forum.com/u/glenn)\
**Post date:** [March 15, 2008, 3:36pm UTC](https://www.ruby-forum.com/t/error-using-fastercsv/132018/2 "2008-03-15T15:36:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![glenn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@glenn](https://www.ruby-forum.com/u/glenn)\
**Post date:** [March 16, 2008, 12:40pm UTC](https://www.ruby-forum.com/t/error-using-fastercsv/132018/3 "2008-03-16T12:40:11Z")

</div>

Hey,

On Sun, Mar 16, 2008 at 1:35 AM, James G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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

---

<div class="post-metadata">

**Author:** ![glenn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@glenn](https://www.ruby-forum.com/u/glenn)\
**Post date:** [March 20, 2008, 9:48am UTC](https://www.ruby-forum.com/t/error-using-fastercsv/132018/4 "2008-03-20T09:48:19Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![glenn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@glenn](https://www.ruby-forum.com/u/glenn)\
**Post date:** [March 16, 2008, 4:51pm UTC](https://www.ruby-forum.com/t/error-using-fastercsv/132018/5 "2008-03-16T16:51:21Z")

</div>

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

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
