# Method definitions and Line numbers

**URL:** <https://www.ruby-forum.com/t/method-definitions-and-line-numbers/52951>\
**Category:** Ruby\
**Created:** [January 21, 2006, 2:15am UTC](https://www.ruby-forum.com/t/method-definitions-and-line-numbers/52951 "2006-01-21T02:15:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bct](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@bct](https://www.ruby-forum.com/u/bct)\
**Post date:** [January 21, 2006, 2:15am UTC](https://www.ruby-forum.com/t/method-definitions-and-line-numbers/52951/1 "2006-01-21T02:15:11Z")

</div>

Hello,

How does Ruby store where methods are defined?  
For example, where does Ruby look to get file names and line numbers in  
the  
stack trace?

---

<div class="post-metadata">

**Author:** ![bct](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@bct](https://www.ruby-forum.com/u/bct)\
**Post date:** [January 21, 2006, 4:45am UTC](https://www.ruby-forum.com/t/method-definitions-and-line-numbers/52951/2 "2006-01-21T04:45:55Z")

</div>

On Jan 20, 2006, at 7:37 PM, Brian T. wrote:

> [http://weblog.freeopinion.org](http://weblog.freeopinion.org)  
> Check out the **FILE** and **LINE** constants.

---

<div class="post-metadata">

**Author:** ![bct](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@bct](https://www.ruby-forum.com/u/bct)\
**Post date:** [January 21, 2006, 7:10am UTC](https://www.ruby-forum.com/t/method-definitions-and-line-numbers/52951/3 "2006-01-21T07:10:59Z")

</div>

> Check out the **FILE** and **LINE** constants.

I apologize for not being clear.

Lets say we have a class Test that raises an error.

class Test  
def method\_with\_an\_error  
raise Error  
end  
end

t = Test.new  
t.method\_with\_an\_error

Now the following error message is outputted in the command line.

/home/btakita/src/scratch3.rb:3:in `method\_with\_an\_error’: Exception  
(Exception)  
from /home/btakita/src/scratch3.rb:8

How does Ruby keep track where :method\_with\_an\_error is stored?  
Can I make a query as to where :method\_with\_an\_error is defined?

---

<div class="post-metadata">

**Author:** ![bct](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@bct](https://www.ruby-forum.com/u/bct)\
**Post date:** [January 21, 2006, 2:16pm UTC](https://www.ruby-forum.com/t/method-definitions-and-line-numbers/52951/4 "2006-01-21T14:16:53Z")

</div>

2006/1/21, Brian T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> ```
> raise Error
> from /home/btakita/src/scratch3.rb:8
> 
> ```
> 
> How does Ruby keep track where :method\_with\_an\_error is stored?  
> Can I make a query as to where :method\_with\_an\_error is defined?

You mean without it raising an excepption? AFAIK there is no other  
way than searching sources for the definition. You can also use $: to  
check directories in the load path.

Wait, there might be one other option: use set\_trace\_func at the  
beginning of your script (before the first require) and record all  
class and method definitions.

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![bct](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@bct](https://www.ruby-forum.com/u/bct)\
**Post date:** [January 21, 2006, 7:14am UTC](https://www.ruby-forum.com/t/method-definitions-and-line-numbers/52951/5 "2006-01-21T07:14:00Z")

</div>

I meant to paste this code:

class Test  
def method\_with\_an\_error  
raise Exception  
end  
end

t = Test.new  
t.method\_with\_an\_error
