# New to ruby: uninitialized constant

**URL:** <https://www.ruby-forum.com/t/new-to-ruby-uninitialized-constant/162869>\
**Category:** Ruby\
**Created:** [March 14, 2009, 7:26pm UTC](https://www.ruby-forum.com/t/new-to-ruby-uninitialized-constant/162869 "2009-03-14T19:26:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ammo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/958977/32.png) [@ammo](https://www.ruby-forum.com/u/ammo)\
**Post date:** [March 14, 2009, 7:26pm UTC](https://www.ruby-forum.com/t/new-to-ruby-uninitialized-constant/162869/1 "2009-03-14T19:26:17Z")

</div>

I have a program the simulates the knights tour problem. I made 2  
classes, 1 called ‘Location’ which simulates a location on a chess board  
and one called ‘KnightsTour’ which actually performs the knights tour.  
Then I have a main.rb file which just creats a knights tour object  
(KnightsTour.new) and calls a method on that object. But whenever i try  
to run it, I get the following error:

C:\NetBeansWorkspace\KnightsTour\lib\main.rb:3:in `const\_missing’:  
uninitialized constant KnightsTour (NameError)  
from C:\NetBeansWorkspace\KnightsTour\lib\main.rb:8

Any help would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![ammo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/958977/32.png) [@ammo](https://www.ruby-forum.com/u/ammo)\
**Post date:** [March 14, 2009, 8:15pm UTC](https://www.ruby-forum.com/t/new-to-ruby-uninitialized-constant/162869/2 "2009-03-14T20:15:58Z")

</div>

Paul Varoutsos wrote:

> Any help would be greatly appreciated.

Do you “require” the files containing the other two classes? Ruby will  
not search for them automatically the way, for example, Java does.

-Justin

---

<div class="post-metadata">

**Author:** ![ammo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/958977/32.png) [@ammo](https://www.ruby-forum.com/u/ammo)\
**Post date:** [March 14, 2009, 9:35pm UTC](https://www.ruby-forum.com/t/new-to-ruby-uninitialized-constant/162869/3 "2009-03-14T21:35:07Z")

</div>

Justin C. wrote:

> Paul Varoutsos wrote:
> 
> > Any help would be greatly appreciated.
> 
> Do you “require” the files containing the other two classes? Ruby will  
> not search for them automatically the way, for example, Java does.
> 
> -Justin

Yes I did

---

<div class="post-metadata">

**Author:** ![ammo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/958977/32.png) [@ammo](https://www.ruby-forum.com/u/ammo)\
**Post date:** [March 15, 2009, 10:08pm UTC](https://www.ruby-forum.com/t/new-to-ruby-uninitialized-constant/162869/4 "2009-03-15T22:08:42Z")

</div>

Paul Varoutsos wrote:

> > Do you “require” the files containing the other two classes? Ruby will  
> > not search for them automatically the way, for example, Java does.
> > 
> > -Justin
> 
> Yes I did

Then it is hard to tell what is going on without seeing your code. This  
error generally means you either have not made the class available or  
there is a typo somewhere, assuming KnightsTour is a class. Or possibly  
you are using it before it is defined.

-Justin
