# Find return value of every executed command

**URL:** <https://www.ruby-forum.com/t/find-return-value-of-every-executed-command/218892>\
**Category:** Ruby\
**Created:** [April 15, 2012, 5:47am UTC](https://www.ruby-forum.com/t/find-return-value-of-every-executed-command/218892 "2012-04-15T05:47:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gurdipe\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b77776/32.png) [@Gurdipe\_D](https://www.ruby-forum.com/u/Gurdipe_D)\
**Post date:** [April 15, 2012, 5:47am UTC](https://www.ruby-forum.com/t/find-return-value-of-every-executed-command/218892/1 "2012-04-15T05:47:47Z")

</div>

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.

> <https://stackoverflow.com/questions/10069967/how-to-detect-variable-changes-assignments-in-ruby>

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
