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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:40:33+00:00 2026-05-16T06:40:33+00:00

How would you list out the modules that have been included in a specific

  • 0

How would you list out the modules that have been included in a specific class in a class hierarchy in Ruby? Something like this:

module SomeModule
end

class ParentModel < Object
  include SomeModule
end

class ChildModel < ParentModel
end

p ChildModel.included_modules #=> [SomeModule]
p ChildModel.included_modules(false) #=> []

Listing the ancestors makes the module appear higher in the tree:

p ChildModel.ancestors #=> [ChildModel, ParentModel, SomeModule, Object, Kernel]
  • 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-16T06:40:34+00:00Added an answer on May 16, 2026 at 6:40 am

    As far as I understand your question, something like this is what you are looking for:

    class Class
      def mixin_ancestors(include_ancestors=true)
        ancestors.take_while {|a| include_ancestors || a != superclass }.
        select {|ancestor| ancestor.instance_of?(Module) }
      end
    end
    

    However, I don’t fully understand your testcases: why is SomeModule listed as an included module of ChildModel even though it isn’t actually included in ChildModel but in ParentModel? And conversely, why is Kernel not listed as an included module, even though it is just as much in the ancestors chain as SomeModule? And what does the boolean argument to the method mean?

    (Note that boolean arguments are always bad design: a method should do exactly one thing. If it takes a boolean argument, it does by definition two things, one if the argument is true, another is the argument is false. Or, if it does only one thing, then this can only mean that it ignores its argument, in which case it shouldn’t take it to begin with.)

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

Sidebar

Related Questions

I have a software diagnostic page on which I would like to list the
I have this specific function to extract parts of a list in the form:
I'm looking for some kind of a resource (website) that would list all possible
How would you list words that are anagrams of each other? I was asked
I thought that to clone a List you would just call: List<int> cloneList =
Would like to get a list of advantages and disadvantages of using Stored Procedures.
I would like to make a list of remarkable robot simulation environments including advantages
I would like to generate a list of files within a directory. Some of
I would like to create a strongly type list and decide the type in
How would I go about generating a list of all possible permutations of a

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.