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

  • Home
  • SEARCH
  • 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 9182767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:38:20+00:00 2026-06-17T18:38:20+00:00

I am trying to extend a module method in a class for a mixin.

  • 0

I am trying to extend a module method in a class for a mixin.

Here is my code:

module Mod_1
    def bar
        puts "xxx"
    end
end

class Class_A
    include Mod_1
    def bar
        super
        puts "yyy"
     end
end

test = Class_A.new
test.bar

The best way of doing I could think of is:

module Mod_1
    def Mod_1.foo
        puts "aaa"
    end
end

class Class_A
    include Mod_1
    def foo
        Mod_1.foo
        puts "bbb"
     end
end

test = Class_A.new
test.foo

Is there a better way I can do this?

  • 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-17T18:38:21+00:00Added an answer on June 17, 2026 at 6:38 pm

    See the below:

    module Bar
        def foo
            puts "first"
        end
    end
    
    class Class_A
        include Bar
        alias old_foo foo
        def foo
            old_foo
            puts "second"
        end
    end
    
    Class_A.new.bar
    

    Returning:

    "first"
    "second"
    

    This uses aliasing. I would recommend looking them up for Ruby specially for something like what you are trying to do.

    Have a read of:
    http://ruby.about.com/od/rubyfeatures/a/aliasing.html

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

Sidebar

Related Questions

I am trying to write a generic module to extend the World class. I
So I am trying extend the base Application class and add member variables to
I'm Trying to extend a non-moose class, and when I call an accessor defined
I am trying to extend the mysqli class to make a helper class that
I'm trying to to define a class called HTML to extend Nokogiri - which
I'm working with the pylibtiff library (hosted here ) and I'm trying to extend
I'm trying to extend a few of my model classes to an Asset class.
I'm trying to extend a method with a single keyword argument while remaining impartial
I'm trying to extend a specific model in my app using railtie. Adding class
I'm trying to abstract case classes in a module using dependent method types and

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.