tags:

views:

69

answers:

1

Hi, Im currently working on a project for my first course in Ruby. A part of the assignment is to have a main class as the one below. I have it in a separate file and the other modules and classes are in separate files. Now Im getting an uninitialized constant Main::Camping (NameError) which I dont get. Any clues to why?! Thanks

Regards

class Main  

if __FILE__ == $0   
    $camping = Camping.new(32, 12)  #creates a new camping     

    include Menus
    $current_menu = main_menu

    # loops through the menu
    while (true)
        puts $current_menu
        choice = Menus.get_input
        $current_menu.make_menu_choice(choice)
    end
end   

end

+1  A: 

Where is the file that defines Camping or 'Menu'? You will need to 'require' those files:

require 'camping'
require 'menus' # etc

class Main
#.. 

Read more about require here.

Swanand
Oh! I forgot, thats true. Now its working, thanks! Did you think that it was strange to us while (true)? You made a comment about it. Regards
Tim
@Tim, consder the construct "loop do...end" as an alternative to "while (true)...end"
Wayne Conrad
@Wayne: do you mean something like this then: loop do puts $current_menu choice = Menus.get_valid_input($current_menu.options) $current_menu.make_menu_choice(choice) end
Tim
@Tim, yes. They do the same thing, but "loop do...end" is more common for endless loops.
Wayne Conrad
@Wayne, thank you for your answer. I looked it up and it worked well. Maybe I should not create an endless loop?! I saw it incorporated with break if as well. Ill see how I will proceed. Regards
Tim
@Tim, Use an endless loop if that seems best. Later, you will develop opinions on whether and when to use endless loops, but it's not time for opinions when you're still learning the basics.
Wayne Conrad
@Wayne, yes I guess you are right about that. As long as it works for me now. And it does. Thanks for your feedback.
Tim
@Wayne: "but it's not time for opinions when you're still learning the basics" Yes, well said.
Swanand