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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:22:30+00:00 2026-05-16T06:22:30+00:00

When sent a message, a Ruby object searches to see whether it has a

  • 0

When sent a message, a Ruby object searches to see whether it has a method by that name to respond with. Its method lookup searches in the following order, and uses the first method it finds.

  1. Singleton methods defined on itself (aka methods on its “eigenclass”)
  2. Methods defined in its class
  3. Any modules mixed into its class, in reverse order of inclusion (only the earliest inclusion of a given module has any effect – if the superclass includes module A, and the subclass includes it again, it’s ignored in the subclass; if the subclass includes A then B then A, the second A is ignored) (update: note that this was written before Module.prepend existed)
  4. Its parent class
  5. Any methods mixed into the parent class, the parent’s parent, etc.

Or, to put it more simply, it looks on itself, then everything in self.class.ancestors in the order they’re listed.

This lookup path is followed at the moment the method is called; if you make an instance of a class, then reopen the class and add a method or mix one in via a module, the existing instance will gain access to that method.

If all of this fails, it looks to see if it has a method_missing method, or if its class does, its parent class, etc.

My question is this: aside from examining the code by hand, or using example methods like puts "I'm on module A!", can you tell where a given method came from? Can you, for example, list an object’s methods and see “this one is on the parent class, this one is on module A, this one is on the class and overrides the parent class,” etc?

  • 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-16T06:22:31+00:00Added an answer on May 16, 2026 at 6:22 am

    Object#method returns a Method object giving meta-data about a given method. For example:

    > [].method(:length).inspect
    => "#<Method: Array#length>"
    > [].method(:max).inspect
    => "#<Method: Array(Enumerable)#max>"
    

    In Ruby 1.8.7 and later, you can use Method#owner to determine the class or module that defined the method.

    To get a list of all the methods with the name of the class or module where they are defined you could do something like the following:

    obj.methods.collect {|m| "#{m} defined by #{obj.method(m).owner}"}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From Apple's Obj-C documentation: If the method returns an object, then a message sent
I have the following jquery function that submits to an iframe. The message sent
Ruby as an Object Oriented Language. What that means is whatever message I send,
How do you 'verify' that a message sent using MSMQ to a private local
I am getting a crash with the following error message: [FilterPurchase respondsToSelector:]: message sent
I am communicating with a server, each message sent to the server has to
I got this error from XCode: objc[8422]: FREED(id): message release sent to freed object=0x3b120c0
The webViewDidFinishLoad message seems to be sent each time any object in the page
I am sending emails with the following method: class Communicate < ActionMailer::Base def message(sub,msg,people)
I am building a ruby application that grabs emails sent to a server 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.