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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:02:43+00:00 2026-05-11T12:02:43+00:00

We recently had a problem where, after a series of commits had occurred, a

  • 0

We recently had a problem where, after a series of commits had occurred, a backend process failed to run. Now, we were good little boys and girls and ran rake test after every check-in but, due to some oddities in Rails’ library loading, it only occurred when we ran it directly from Mongrel in production mode.

I tracked the bug down and it was due to a new Rails gem overwriting a method in the String class in a way that broke one narrow use in the runtime Rails code.

Anyway, long story short, is there a way, at runtime, to ask Ruby where a method has been defined? Something like whereami( :foo ) that returns /path/to/some/file.rb line #45? In this case, telling me that it was defined in class String would be unhelpful, because it was overloaded by some library.

I cannot guarantee the source lives in my project, so grepping for 'def foo' won’t necessarily give me what I need, not to mention if I have many def foo‘s, sometimes I don’t know until runtime which one I may be using.

  • 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. 2026-05-11T12:02:43+00:00Added an answer on May 11, 2026 at 12:02 pm

    This is really late, but here’s how you can find where a method is defined:

    http://gist.github.com/76951

    # How to find out where a method comes from. # Learned this from Dave Thomas while teaching Advanced Ruby Studio # Makes the case for separating method definitions into # modules, especially when enhancing built-in classes. module Perpetrator   def crime   end end  class Fixnum   include Perpetrator end  p 2.method(:crime) # The '2' here is an instance of Fixnum. #<Method: Fixnum(Perpetrator)#crime> 

    If you’re on Ruby 1.9+, you can use source_location

    require 'csv'  p CSV.new('string').method(:flock) # => #<Method: CSV#flock>  CSV.new('string').method(:flock).source_location # => ['/path/to/ruby/1.9.2-p290/lib/ruby/1.9.1/forwardable.rb', 180] 

    Note that this won’t work on everything, like native compiled code. The Method class has some neat functions, too, like Method#owner which returns the file where the method is defined.

    EDIT: Also see the __file__ and __line__ and notes for REE in the other answer, they’re handy too. — wg

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

Sidebar

Related Questions

I've recently had a horrible problem with QTCreator. After the first time of running
We recently had a problem with an application upgrade on Android Market. Namely, after
I had recently a problem with oom-killer starting to kill processes after some time.
I had a problem recently with some devices after I upgraded to SDK Tools
Recently I had a problem in a costumer's computer. Our installer would hang during
Here's a problem I've had recently that just HAS to be a common pain
I recently had a similar thread about this, but now I need to animate
I recently had a problem creating a stringstream due to the fact that I
I've recently had to uninstall/re-install my .NET Framework 4 after finding my current installation
Recently I had some problem in performance of my query. The thing is described

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.