I'm trying to write a game in Ruby (not Rails) as a way to teach it myself better. (Sense, I would like to do it right, but if I try to teach something that just won’t work in Ruby, I will switch languages.) I have a problem with ordering, and I wonder if there is a clean way to do it following.
Here is my structure:
game Gemfile src models character.rb game_object.rb init.rb
Instead of listing each file separately, init.rb requires these files:
Dir['./src/**/*.rb'].each do |app| require app end
game_object.rb is still very simple, but character.rb looks like this:
module Game class Character < Game::GameObject attr_accessor :name def initialize(name) @name = name end end end
Unfortunately, if I do this, I get a "uninitialized constant Game :: GameObject (NameError)", unless I explicitly require a game for other files.
It seems to me that I have several options:
- Load game_object (and other superclasses) into init.rb before the others.
- Requiring game_object in character.rb, which seems problematic, because depending on which path I use, I understand that it can download the file several times.
- Download each file separately and manage the order completely manually, so that I have full control.
It all seems more complicated than it should be. Is there a cleaner way?
source share