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 7771101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:33:56+00:00 2026-06-01T16:33:56+00:00

If I load x.rb , then all the classes in that file are loaded

  • 0

If I load x.rb, then all the classes in that file are loaded. Is it possible to check and see what classes are being used and load those only?

Assuming x.rb contains both Hello and Goodbye classes, and my program only uses the Hello Class, is it possible to load only the Hello Class?

Happy with a script that checks the document, and outputs an .rb that has only the Hello Class and the code that uses it… Would be an interesting github project if doesn’t exist, but I think it’s out of my skillset atm.

  • 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-06-01T16:33:57+00:00Added an answer on June 1, 2026 at 4:33 pm

    When classes are defined in their own separate file, you could use the autoload¹² method:

    autoload :Hello,   'x/hello'
    autoload :Goodbye, 'x/goodbye'
    

    When you write Hello, you are actually accessing the Hello constant. autoload uses const_missing to automatically require a file if the constant is not defined.

    Note that we are still dealing with files here. The contents of x/hello.rb will simply be read and evaluated. That code can run any operation. It can require other files. It could define a million other classes.

    That’s because source code is really just text. This is especially true for interpreted languages. For example, in Java, you can usually only declare one public type per “compilation unit”. In Ruby, there is no such thing.


    ¹ Matz strongly discourages the practice

    ² Ruby Inside article on autoload

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

Sidebar

Related Questions

Currently I load in all my classes by including a all.inc.php file on every
All the simple examples of geocoding load a hard-coded long/lat pair and then, after
Is there any way that I can use C# to load and then render
I'm trying to create a widget within the module and then load that widget
I'm trying to deserialize an XML sitemap and then load it into a Datagrid
I expect the following code to unload a javascipt jqgrid, then load another grid
I'm trying to load page and then remove some elements in it. While doing
Every now and then Elastic Load Balancer (ELB) kicks out one of my servers
I create a iframe in a div by jQuery.Then I load another page(lets say
I have a data structure object which is loaded from an XML file inside

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.