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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:47:47+00:00 2026-06-13T15:47:47+00:00

I am using Ruby 1.9.2 and the Ruby on Rails v3.2.2 gem. I would

  • 0

I am using Ruby 1.9.2 and the Ruby on Rails v3.2.2 gem. I would like to “nest” the inclusion of modules given I am using the RoR ActiveSupport::Concern feature, but I have a doubt where I should state the include method. That is, I have the following:

module MyModuleA
  extend ActiveSupport::Concern

  # include MyModuleB

  included do
    # include MyModuleB
  end
end

Should I state include MyModuleB in the “body” / “context” / “scope” of MyModuleA or I should state that in the included do ... end block? What is the difference and what I should expect from that?

  • 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-13T15:47:48+00:00Added an answer on June 13, 2026 at 3:47 pm

    If you include MyModuleB in the “body” of MyModuleA, then it is the module itself that is extended with B’s functionality. If you include it in the included block, then it is included on the class that mixes in MyModuleA.

    That is:

    module MyModuleA
      extend ActiveSupport::Concern
      include MyModuleB
    end
    

    produces something like:

    MyModuleA.send :include, MyModuleB
    class Foo
      include MyModuleA
    end
    

    while

    module MyModuleA
      extend ActiveSupport::Concern
      included do
        include MyModuleB
      end
    end
    

    produces something like:

    class Foo
      include MyModuleA
      include MyModuleB
    end
    

    The reason for this is that ActiveSupport::Concern::included is analogous to:

    def MyModuleA
      def self.included(klass, &block)
        klass.instance_eval(&block)
      end
    end
    

    The code in the included block is run in the context of the including class, rather than the context of the module. Thus, if MyModuleB needs access to the class it’s being mixed-in to, then you’d want to run it in the included block. Otherwise, it’s effectively the same thing.

    By means of demonstration:

    module A
      def self.included(other)
        other.send :include, B
      end
    end
    
    module B
      def self.included(other)
        puts "B was included on #{other.inspect}"
      end
    end
    
    module C
      include B
    end
    
    class Foo
      include A
    end
    
    # Output:
    # B was included on C
    # B was included on Foo
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Ruby on Rails and the Capistrano gem. I would like to
I am using Ruby on Rails 3.2.2 and the I18n 0.6.0 gem. I would
I am using Ruby on Rails 3.1 and I would like to know how
I am using Ruby on Rails 3.0.9 and I would like to seed the
I am using Ruby 1.9.2 and the Ruby on Rails v3.2.2 gem. I would
I am using Ruby on Rails 3.0.7 and I would like to install and
I am using Ruby on Rails 3.2.2 and Paperclip 2.7.0. I would like to
I am using Ruby on Rails 3.0.9 and I would like to publish my
I am using Ruby on Rails 3.1.0 and the rspec-rails 2 gem. I would
I am using Ruby on Rails 3.1.0 and the rspec-rails 2 gem. I would

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.