Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6944841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:21:34+00:00 2026-05-27T13:21:34+00:00

I’m trying to write a game in Ruby (not Rails) as a way to

  • 0

I’m trying to write a game in Ruby (not Rails) as a way to teach it to myself better. (Meaning, I’d like to do this right, but if I’m trying to shoehorn something that just won’t work into Ruby, I’ll switch languages.) I’m running into a problem with require order, and I’m wondering if there’s a clean way to do the following.

Here’s my structure so far:

game
  Gemfile
  src
    models
      character.rb
      game_object.rb
  init.rb

Instead of listing each file individually, init.rb requires files like this:

  Dir['./src/**/*.rb'].each do |app|
    require app
  end

game_object.rb is, so far, 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 that, I get “uninitialized constant Game::GameObject (NameError)”, unless I explicitly require game_object before other files.

It seems to me that I have a few options here:

  1. Load game_object (and other superclassees) in init.rb before others.
  2. Require game_object in character.rb, which seems problematic because depending on which path I use, my understanding is that it may load the file multiple times.
  3. Load each file individually and manage the order completely manually so I have full control.

These all seem to be more complicated than it should be. Is there a cleaner way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:21:35+00:00Added an answer on May 27, 2026 at 1:21 pm

    Just putting it out there: more code does not mean “dirty”, just as often as less code does not mean “clean.”

    Requiring your files manually will give you less headache in the long run—it solves load order issues and prevents you from requiring files you don’t actually want. Plus, anyone looking at your code later on has a nice, clean manifest of what’s being loaded in your app.

    My suggestions:

    1. Drop the src folder, it’s redundant—your Ruby app is all source.
    2. Map your namespaces to folders
    3. Use explicit requires (this becomes easier when you use #2:

    Example:

    game/
      bin/
        gamerunner
      Gemfile
      lib/
        game.rb
        game/
          game_object.rb
      models/
        character.rb
      spec/
        spec_helper.rb
        models/
          character_spec.rb
    

    You are writing specs / tests, aren’t you?

    Then, in lib/game.rb:

    require 'game/game_object.rb'
    # require the rest of your library as you build it
    
    module Game
    end
    

    And in your init:

    require 'game'
    require 'models/character.rb'
    

    Much cleaner, much easier to extract from later on and should solve your problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.