# Given I know where a method is defined, I want to know where its called (at runtime)

**URL:** <https://www.ruby-forum.com/t/given-i-know-where-a-method-is-defined-i-want-to-know-where-its-called-at-runtime/206575>\
**Category:** Rails\
**Created:** [May 5, 2011, 3:39am UTC](https://www.ruby-forum.com/t/given-i-know-where-a-method-is-defined-i-want-to-know-where-its-called-at-runtime/206575 "2011-05-05T03:39:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [May 5, 2011, 3:39am UTC](https://www.ruby-forum.com/t/given-i-know-where-a-method-is-defined-i-want-to-know-where-its-called-at-runtime/206575/1 "2011-05-05T03:39:09Z")

</div>

Hey all, application completely breaks down in production mode. I  
followed the execution file by file line by line and yet I cannot figure  
out where an instance variable is being generated from. But I have a  
suspicion. This method right here:

# neeeded becasuse of a rails bug

def to\_s  
“#{self.class.name.underscore}\_\_#{object\_id}”  
end

I think it’s cause of problem. I also noticed that the developer left a  
comment above it. Problem is it’s part of a class that gets yielded into  
a ruby block and there’s a number of partials that get rendered in the  
new view. But I cannot find for the life of me where to\_s is called  
during execution of clicking a new button.

I need some debugging advice for this.

Thanks for response.

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [May 5, 2011, 3:49am UTC](https://www.ruby-forum.com/t/given-i-know-where-a-method-is-defined-i-want-to-know-where-its-called-at-runtime/206575/2 "2011-05-05T03:49:48Z")

</div>

On May 4, 2011, at 6:39 PM, John M. wrote:

> I think it’s cause of problem. I also noticed that the developer left a  
> comment above it. Problem is it’s part of a class that gets yielded into  
> a ruby block and there’s a number of partials that get rendered in the  
> new view. But I cannot find for the life of me where to\_s is called  
> during execution of clicking a new button.
> 
> I need some debugging advice for this.

caller() should help…

[http://www.ruby-doc.org/core/classes/Kernel.html#M001397](http://www.ruby-doc.org/core/classes/Kernel.html#M001397)

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [May 5, 2011, 4:04am UTC](https://www.ruby-forum.com/t/given-i-know-where-a-method-is-defined-i-want-to-know-where-its-called-at-runtime/206575/3 "2011-05-05T04:04:41Z")

</div>

Philip H. wrote in post #996721:

> On May 4, 2011, at 6:39 PM, John M. wrote:
> 
> > I think it’s cause of problem. I also noticed that the developer left a  
> > comment above it. Problem is it’s part of a class that gets yielded into  
> > a ruby block and there’s a number of partials that get rendered in the  
> > new view. But I cannot find for the life of me where to\_s is called  
> > during execution of clicking a new button.
> > 
> > I need some debugging advice for this.
> 
> caller() should help…
> 
> [http://www.ruby-doc.org/core/classes/Kernel.html#M001397](http://www.ruby-doc.org/core/classes/Kernel.html#M001397)

It appears caller expects an argument. This is not a setter method.  
There is no argument passed to this object, and in your example, if i  
add one like ‘skip’, of course I receive an exception “wrong number of  
arguments”.

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [May 5, 2011, 10:29am UTC](https://www.ruby-forum.com/t/given-i-know-where-a-method-is-defined-i-want-to-know-where-its-called-at-runtime/206575/4 "2011-05-05T10:29:03Z")

</div>

On 5 May 2011 02:39, John M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I think it’s cause of problem. I also noticed that the developer left a  
> comment above it. Problem is it’s part of a class that gets yielded into  
> a ruby block and there’s a number of partials that get rendered in the  
> new view. But I cannot find for the life of me where to\_s is called  
> during execution of clicking a new button.
> 
> I need some debugging advice for this.

If all else fails put some code there that generates a runtime error,  
then you will get a stack trace. If you only want it to stop under  
some conditions use a global variable and test it at the offending  
point to find out whether to crash or not.

Fred’s suggestion of using ruby-debug and putting a (possibly  
conditional) breakpoint there is probably better.

Colin

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [May 6, 2011, 2:54am UTC](https://www.ruby-forum.com/t/given-i-know-where-a-method-is-defined-i-want-to-know-where-its-called-at-runtime/206575/5 "2011-05-06T02:54:50Z")

</div>

> The argument to caller is optional. You might also want to install  
> ruby-debug and add a breakpoint.
> 
> Fred

Yeah kind of like breakpoint in C++. Thanks for response.

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [May 5, 2011, 9:24am UTC](https://www.ruby-forum.com/t/given-i-know-where-a-method-is-defined-i-want-to-know-where-its-called-at-runtime/206575/6 "2011-05-05T09:24:50Z")

</div>

On 5 May 2011, at 03:04, John M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > caller() should help…
> > 
> > [http://www.ruby-doc.org/core/classes/Kernel.html#M001397](http://www.ruby-doc.org/core/classes/Kernel.html#M001397)
> 
> It appears caller expects an argument. This is not a setter method.  
> There is no argument passed to this object, and in your example, if i  
> add one like ‘skip’, of course I receive an exception “wrong number of  
> arguments”.

The argument to caller is optional. You might also want to install  
ruby-debug and add a breakpoint.

Fred
