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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:43:14+00:00 2026-06-07T06:43:14+00:00

I was under the impression that obj.method caused ruby to look for method thusly:

  • 0

I was under the impression that obj.method caused ruby to look for method thusly:

  1. Look in obj‘s singleton class.
  2. Look in the modules included by obj‘s singleton class.
  3. Look in obj‘s class.
  4. Look in the modules included by obj‘s class
  5. repeat steps 3 and 4 on the class’s superclass until found
  6. If never found, call method_missing on the original object, obj.

Under this model, the only singleton class searched for the method is the singleton class of the original receiver, obj. However, this model can’t explain the fact that a subclass can access its superclass’s singleton methods. For example

class Foo
  def self.foo
    "foo"
  end
end

class Bar < Foo
end

Bar.foo  #=> "foo"

I’m confused because I believe this means that Foo‘s singleton class is at some point searched for the method foo. However, under the model above, I would expect that only Bar‘s singleton class would be searched for foo. Failing that, I would expect ruby to look in Bar‘s class, Class, and then continue crawling up the superclass chain (skipping Foo and its singleton class completely).

So my question: what is missing from my understanding of Ruby method lookup which explains the fact that a class can access its superclass’s singleton methods?

  • 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-07T06:43:16+00:00Added an answer on June 7, 2026 at 6:43 am

    When subclassing, not only is Bar.superclass set to Foo, but the same holds true for the singleton classes:

    Bar.singleton_class.superclass == Foo.singleton_class  # => true
    

    So you’re not really confused. The actual lookup is:

    1. Start with obj‘s singleton class.
    2. Look for instance methods down the ancestor list:
      • prepended modules (Ruby 2.0)
      • the class itself
      • included modules
    3. Repeat #2 with superclass.
    4. Repeat #1 but this time looking for method_missing
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had been under the impression that in a C++/CLI method if a class
I was under the impression that using the Resolve method returned a new instance
I was under the impression that singleton is the proper design pattern which adds
I was under the impression that the format() function of the PHP DateTime class
I was under the impression that Microsoft Test Manager 2010 was included in Microsoft
This is driving me crazy. I am under the impression that awakeFromNib Method is
I was under the impression that when we send mail to any domain (i.e.
I'm under the impression that a control in a nested UpdatePanel will cause the
I was under the impression that when you called Flush() in a StreamWriter object
I was under the impression that I could get the value of a select

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.