Forum: Ruby new to ruby: uninitialized constant

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E737d7f64f5f4b68ef2e5735d62f4891?d=identicon&s=25 Paul Varoutsos (ammo)
on 2009-03-14 19:26
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.
6e366eb5a71be2bad7f383d42aeb4788?d=identicon&s=25 Justin Collins (Guest)
on 2009-03-14 20:15
(Received via mailing list)
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
E737d7f64f5f4b68ef2e5735d62f4891?d=identicon&s=25 Paul Varoutsos (ammo)
on 2009-03-14 21:35
Justin Collins 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
6e366eb5a71be2bad7f383d42aeb4788?d=identicon&s=25 Justin Collins (Guest)
on 2009-03-15 22:08
(Received via mailing list)
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
This topic is locked and can not be replied to.