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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:19:11+00:00 2026-05-23T19:19:11+00:00

Here is what my code looks like: module A def foo puts A end

  • 0

Here is what my code looks like:

module A
  def foo
    puts "A"
  end
end

module B
  include A
  def bar
    foo
  end
end

class MyClass
  include B
  def foo
    puts "X"
  end
  def self.test
    puts bar
  end
end

When I call “C.test” I get “X” instead of “A” (which is what I want) because the local definition of foo has overridden that in A. I can’t change the signature of either foo’s. I can only mainly edit my own class; I can edit modules A and B but lots of existing code use them and they are (so no changing foo to A.foo for instance). I am thinking of doing

class MyClass
  module MyModules
    include B
  end
  ....
    MyModules.bar
  ....
end

But this does not work.

How can I “localize” the namespace when doing include 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-05-23T19:19:12+00:00Added an answer on May 23, 2026 at 7:19 pm

    I found a solution for what I wanted, might not be the best answer but works exactly the way I want it to.

    class MyClass
      class MyModules
        extend B
      end
      ....
        MyModules.bar
      ....
    end
    

    This effectively allows me to limit the scope of B and all other included modules in the local class MyModules. In my code it actually has a meaning because all the included modules handle expression manipulation so I can call the local class “Expr” (and they are seriously overusing the names ‘eval’, ‘bind’ and ‘free’ right now).

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

Sidebar

Related Questions

here is what my code looks like i have two forms: class Form_1 extends
So I have some PHP code that looks like: $message = 'Here is the
I have a Python 2.x module.py file that looks like this: class A(object): KEYWORD
I'm looking for something like break for loops. Here's some example code (using Symfony's
EDIT - The code looks strange here, so I suggest viewing the files directly
Here a code to demonstrate an annoying problem: class A { public: A(): m_b(1),
I'm struggling with code that looks like the example below (but actually does something
I'd like to 'add on' some code on a model's method via a module,
Have a look here: In the following code, what would be the type of
am new here. i have a slight problem; PLease look at the following code

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.