Trace code in Ruby?

Is there a good way to run a script and see all the steps:

  • What code is executed
  • Which file is in
  • What does he return
  • Error messages

This will be a good way to find out how an open source project works.

Are there no such solutions for Ruby?

Eg.

require "httparty" HTTParty.get "http://www.google.se" 

Then it will run the code and show me all the code that it runs, in which the file and line, the returned objects, error messages, etc.

+6
debugging ruby open-source tracing
source share
4 answers

Tracer can do it for you http://en.wikibooks.org/wiki/Ruby_Programming/Standard_Library/Tracer

if you want to just see the exceptions thrown, then run ruby ​​-d (or use ruby-debug and "Catch" Exception)

+5
source share

There is Kernel#set_trace_func , which basically covers what you need:

proc takes up to six parameters: event name, file name, line number, object identifier, binding, and class name. proc is called whenever an event occurs.

I am not sure, however, what you mean by "error messages." If you refer to exceptions, if you do not handle them in your code, your code will end with a printed exception.

+2
source share

use debugger? ruby comes with one built-in or uses ruby-debug

0
source share

You can raise an exception, catch it, and then use the backtrace method of the Exception object.

0
source share

All Articles