Method definitions and Line numbers

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?

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

http://weblog.freeopinion.org
Check out the FILE and LINE constants.

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?

2006/1/21, Brian T. [email protected]:

    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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs