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

The Archive Base Latest Questions

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

I understand the regular method lookup path i.e. class, superclass/module, all the way up

  • 0

I understand the regular method lookup path i.e. class, superclass/module, all the way up to BasicObject. I thought it was true for singleton version of the chain also but doesn’t seem the case when you mixin a module in the meta-chain. I’d appreciate if someone can explain why in the following example Automobile module’s banner method is called instead of its singleton version when I have included this module in Vehicle’s eigenclass.

module Automobile
  def banner
    "I am a regular method of Automobile"
  end

  class << self
    def banner
      "I am a class method of Automobile"
    end
  end
end

class Vehicle 
  def banner
    "I am an instance method of Vehicle"
  end

  class << self
    include Automobile
    def banner
      puts "I am a class method of Vehicle"
      super
    end
  end
end

class Car < Vehicle
  def banner
    "I am an instance method of Car"
  end

  class << self
    def banner
      puts "I am a class method of Car"
      super
    end
  end
end

puts Car.banner

# I am a class method of Car
# I am a class method of Vehicle
# I am a regular method of Automobile
  • 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-13T23:09:47+00:00Added an answer on June 13, 2026 at 11:09 pm

    First of all, include does not include eigenclass methods as you might expect. Consider:

    module Foo
      class << self
        def do_something
          puts "Foo's eigenclass method does something"
        end
      end
    end
    
    module Bar
      include Foo
    end
    
    puts Bar.do_something
    # undefined method `do_something' for Bar:Module (NoMethodError)
    

    Note that this is consistent with the behavior of classically defined class methods:

    module Foo
      def self.do_something
        puts "Foo's class method does something"
      end
    end
    
    module Bar
      include Foo
    end
    
    puts Bar.do_something
    # undefined method `do_something' for Bar:Module (NoMethodError)
    

    A common idiom is to define the class methods in a submodule and then trigger a call to extend when the module is included:

    module Foo
      def self.included(base)
        base.extend ClassMethods
      end
    
      module ClassMethods
        def do_something
          puts "Foo::ClassMethod's instance method does something"
        end
      end
    end
    
    module Bar
      include Foo
    end
    
    puts Bar.do_something
    # Foo::ClassMethod's instance method does something
    

    The second thing to note is, that you are really including the instance methods of Automobile into the eigenclass of Vehicle, thus the instance methods of Automobile turn into (eigen)class methods of Vehicle.

    Your Car class basically has nothing to do with all this. The only thing to note here is, that class inheritance also makes class methods available, whereas include does not. Example:

    class Foo
      def self.do_something
        puts "Foo's class method does something"
      end
    end
    
    class Bar < Foo
    end
    
    puts Bar.do_something
    # "Foo's class method does something"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understand, in a fuzzy sort of way, how regular ACID transactions work. You
I really don't understand regular expressions and was wondering what the following regular expressions
I understand the regular fixed-point type combinator and I think I understand the higher-order
I understand PCRE pretty well, but MySQL's regular expression flavor seems to get the
There is something I don't understand in Java's regular expressions. I have the following
I'm not very knowledgeable with regular expresions, so I don't understand why I'm getting
Started learning algorithms. I understand how to find theta-notation from a 'regular recurrence' like
I understand, from MSDN, that ClassInitialize is to mark a method that will do
This is something I don't understand. Look at this method (copied from http://blog.blackwhale.at/2009/07/uibutton-in-uitableview-footer/ )
I have an applet which contains some images, regular java classes and class, which

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.