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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:23:32+00:00 2026-06-12T01:23:32+00:00

I am trying to understand the include statement behavior when used in multiple Mixins.

  • 0

I am trying to understand the include statement behavior when used in multiple Mixins. That is, I have these statements:

class Article < ActiveRecord::Base
  include DoubleIncludedModule
  include AModule

  # ...
end

module AModule
  include DoubleIncludedModule

  # ...
end

module DoubleIncludedModule
  # ...
end

How many times will be the DoubleIncludedModule included in the Article class? That is, since the “subsequent” inclusion of the DoubleIncludedModule (first in the Article class and then in AModule included by the Article class itself), will be the “double inclusion” issue automatically handled by Ruby or will the DoubleIncludedModule (wrongly) included two times?

Of course, I would like to include the DoubleIncludedModule module only one time. How can I make that (maybe by using some Ruby on Rails methods) the proper 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-06-12T01:23:33+00:00Added an answer on June 12, 2026 at 1:23 am

    I’ll answer with an example:

    module A
      def self.included base
        puts "A included in #{base}"
      end
    end
    
    module B
      include A
    
      def self.included base
        puts "B included in #{base}"
      end
    end
    
    class C
      include A
      include B
    end
    
    p C.ancestors
    

    prints

    A included in B
    A included in C
    B included in C
    [C, B, A, Object, Kernel, BasicObject]
    

    As we can see, A is included only once into C. Though technically it was included twice since it was included into B which was also included into C. Does this matter? Probably not. Each still only occurs once in the ancestor chain, and any methods would’ve been overridden with equivalent implementations—i.e., essentially a no-op. Unless you’re doing something exotic with the included hook, you’re unlikely to notice anything.

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

Sidebar

Related Questions

I am trying to understand functions returning a reference. For that I have written
I have been trying to understand of this following C-program: #include <stdio.h> int arr[]
I am trying to understand the following code: #include<stdio.h> #include<stdlib.h> #include<sys/io.h> #define baseport 0x378
I'm trying to include the Sparkle framework in my application. I don't really understand
I am trying understand ViewModels deeper and I have read many articles and blogs
Basically, I'm trying to understand the difference between the Break in Class Module and
I am trying to understand this code: #include<stdio.h> int main() { extern int a;
I am trying to understand why my program #include<stdio.h> void main() { printf(%x,-1<<4); }
I'm trying to understand how returning a pointer works in the following scenarios: #include
I was trying to understand forks, and tried following in C: #include<stdio.h> #include <unistd.h>

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.