views:

59

answers:

4

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

  • Which code is executed
  • Which file the code is in
  • What it returns
  • The error messages

This would be a good way to learn how an open source project is working.

Aren't there solutions like this for Ruby?

Eg.

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

Then it would run the code and show me all the code it is executing, in which file and line, returned objects, error messages etc.

A: 

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

banister
Does a debugger like ruby-debug do what I need? Please read my updated post.
never_had_a_name
A: 

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

Dmitry Maksimov
I'm not the guy who coded the library. Read my updated post
never_had_a_name
+1  A: 

There is Kernel#set_trace_func which mostly covers what you require:

proc takes up to six parameters: an event name, a filename, a line number, an object id, a binding, and the name of a class. proc is invoked whenever an event occurs.

I'm not sure, though, what do you mean by "the error messages". If you refer to exceptions, if you don't handle them in your code, your code will terminate with the exception printed.

Mladen Jablanović
Read my updated post
never_had_a_name
+1  A: 

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

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

rogerdpack
I'm using Ruby 1.9.2. Why is there no -rtracer switch when i run "ruby --help". And when I run "ruby -rtracer my_ruby_file.rb" it is printed out just as usual, I see no tracing functionality.
never_had_a_name