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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:03:19+00:00 2026-06-01T07:03:19+00:00

I am looking into catching every method that is defined on a base class,

  • 0

I am looking into catching every method that is defined on a base class, looking up what file it is defined in, and then doing some logic based on that.

I currently have:

  # Defined in some file
  class Subclass < Base
    def foo
    end
  end


  class Base
    self.method_added(method)
      # self is a given subclass (Subclass)

      # This doesn't work. :(
      self.method(method).source_location
    end
  end

What I’d like to be able to do is find out the source location of that method.

I could do something like:

self.new.method(source).source_location

But don’t think I should be having to instantiate anything to get this to work.

Any ideas?

  • 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-01T07:03:21+00:00Added an answer on June 1, 2026 at 7:03 am

    You can use method Module#instance_method to get instance method of your class:

    instance_method(method).source_location  # `self` is unnecessary, it is added implicitly
    # => ["/home/alex/Projects/test/test.rb", 23]
    

    instance_method(symbol) → unbound_method

    Returns an UnboundMethod representing the given instance method in mod.

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

Sidebar

Related Questions

We're currently looking into doing some performance tweaking on a website which relies heavily
I've been looking into Varnish recently and doing some heavy Google searching. We've recently
Looking into selector performance between $('#ID1, #ID2, #ID3') vs $('1X CLASS'). Which is faster?
By looking into the Open JPA website i've found that i can log the
I am working on catching errors in my app, and I am looking into
I'm looking into creating an Web or iPad application that will use HTML5. After
I have a colleague who is looking into opcode caching/Zend Acceleration (I've always assumed
Currently looking into learn new technology and silverlight is on the potential list. However,
Am looking into developing an iPhone native app using Titanium Developer Since this is
I looking into making a kind of robot testing browser. Like Selenium, but one

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.