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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:04:46+00:00 2026-05-19T22:04:46+00:00

Supposing I have the following: module A class B # … end # …

  • 0

Supposing I have the following:

module A
  class B
    # ...
  end

  # ...
end

And suppose I have several different files like this, with different values of B, but all in the same module (A). From a program that require‘s a file that then require‘s each of these files, is there a way with introspection/reflection (are these different things? I’m hazy on the distinction, if so) to determine (and get objects for) each class within the module?

I’ve tried this, which gets me sort of close:

A.constants # => ["B"]

But I’d prefer to get back [A::B], rather than a string, so that I can then call something like singleton_methods on it, which would be useful to my program, which is attempting to map data into calls into the various subclasses’ methods.

Is there some way to do this? I’ve been digging for answers, and found a few related things, like this or this, but nothing that’s quite spot on.

  • 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-19T22:04:46+00:00Added an answer on May 19, 2026 at 10:04 pm

    Hah! Wouldn’t you know it? Just after writing this, I discovered an answer that seems to work for me:

    A.constants.collect{|k| A.const_get(k)}.select {|k| k.is_a?(Class)} # => [A::B]
    

    Sweet, that was easy, once I put the right pieces together. 🙂

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

Sidebar

Related Questions

Supposing to have something like this: #include <map> int main(){ std::map<int,int> m; m[1] =
What's the object type returned by Datepicker? Supposing I have the following: $(#txtbox).datepicker({ onClose:
I have to detect port aggregation configuration on Linux. Supposing that the ifcfg-* files
Supposing I'm setting a background image for a web page in CSS like this:
Supposing we have the following records in an SQL Server table. Date 19/5/2009 12:00:00
Supposing I have the following type from an external library: union foreign_t { struct
Supposing I have a function with following signature: Foo[] getSomeFoos() { //return null ---
Supposing I have some random block of text in a single line. Like so
I'm sure I'm going to have to write supporting javascript code to do this.
I have the following code implementation of Breadth-First search. trait State{ def successors:Seq[State] def

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.