Find return value of every executed command

Hi,
I’m playing around trying to make a tool to aid in debugging. I’m
focussed on ruby 1.9.3

Is there a way to run some code after each line of code is executed by
the interpreter?

I have tried set_trace_func(), but that seems to execute code before the
line is executed eg.

At that stage I was looking for variable changes, but now I think just
the return value of the line would suit my purposes. Is there a way to
get this?

As the first stage to this project, I would just like to trace every
line of output to a file, so for example;

v = “cool”
f = 5
(1…2).each do |x|
f = x
end

would output;
line 1 => “cool”
line 2 => 5
line 4 => 1
line 4 => 2

Does anyone have any ideas on how this could be done? I have been
playing with irb, pry, debugger etc. and can’t find any example code
that actually does what I need.

Cheers,
Anko