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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:47:35+00:00 2026-06-07T20:47:35+00:00

module A; def a; end; end module B; def b; end; end class C;

  • 0
module A; def a; end; end
module B; def b; end; end

class C; include A; end

module A; include B; end
class D; include A; end

C.new.b # undefined method error
D.new.b # nil

C.ancestors # [C, A, Object...]
D.ancestors # [D, A, B, Object...]

How to include module B inside of A, so that classes that already include module A will also get methods from module B?

  • 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-07T20:47:37+00:00Added an answer on June 7, 2026 at 8:47 pm

    You can’t.

    When you include a mixin M into a class C, Ruby creates a new class ⟦M′⟧ whose method table points to the method table of the mixin M and whose superclass is the superclass of C, then makes this class the new superclass of C. This is repeated for every mixin that was mixed into M.

    Note that this algorithm is run only once, when you mix M into C. Modules that get included later, will not get considered.

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

Sidebar

Related Questions

module Test def self.model_method puts this is a module method end end class A
I have method that returns module path of given class name def findModulePath(path, className):
module MyModule def my_method; 'hello'; end end class MyClass class << self include MyModule
class Foo def initialize(a) puts Hello #{a} end end module Bar def initialize(b) puts
Given the following module, module Foo def bar :baz end end def send_to_foo(method) #
I'm trying to figure why this code: class BaseClass end module Extensions def self.included(base)
With the following code: class ObjA def func puts ObjA end end module Mod
I have a couple of modules that extend method missing: module SaysHello def respond_to?(method)
When I call self.class.instance_variable_set(@var, ...) from inside a class method, where is that variable
Is there a way to include a module to a class such that the

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.