0

Say I have a variable called @test_var

And I have hundred lines of code using this variable

On debugging I need to give n for next step and @test_var to check the value

Can I do both in single command (i.e) print the value of a variable on every step ?

Siva
  • 7,780
  • 6
  • 47
  • 54

3 Answers3

1

You are looking for

display @test_var

After that, @test_var will be printed every time the debugger stops.

deivid
  • 4,808
  • 2
  • 33
  • 38
0

If you want to print it in controller then

for each line give one heading like

p "step 1"
p @test_var

p "step 2"
p @test_var
Debadatt
  • 5,935
  • 4
  • 27
  • 40
  • Well I gave that case for example, but the real situation is in production with tons of code – Siva Oct 31 '13 at 12:41
  • we can divided tons of code into multiple methods, also we can take use of helpers. If it is not an old code, then its good to divided into multiple private methods as per their usuability. – Debadatt Oct 31 '13 at 12:49
  • Are you telling to add `print` to every line ? – Siva Oct 31 '13 at 13:02
  • Not mandatory to give print to every line.. hope u could think from a shorter part of the code where the @variable value may change and print there – Debadatt Oct 31 '13 at 13:06
0

My own solution to print and debug variables is https://github.com/igorkasyanchuk/wrapped_print

you can simply call @test_var.wp to see in the logs a value of this variable

Igor Kasyanchuk
  • 766
  • 6
  • 12