7

I'm using Ruby 2.2.2, Pry and 'pry-byebug'. The continue statement removes any watched variables in have in pry-byebug:

[1] pry(main)> watch foo
Watching foo
watch: foo => 42
[2] pry(main)> watch
Listing all watched expressions:

1: foo => 42

[3] pry(main)> continue
[1] pry(main)> watch
No watched expressions

Losing them on every continue makes watched expressions pretty worthless. If I use next and step to the same point in the code instead, the watched expressions are still there; it's just the continue that causes the problem. At the moment I can't even find any documentation on the watch statement, so I don't know why this occurs.

More generally, I just want to print out the value of a set of expressions on every Pry prompt (or, perhaps, print them out if they've changed since the last time they were printed.) How can I achieve this in a Ruby debugger?

Sasgorilla
  • 2,403
  • 2
  • 29
  • 56
  • The integration of byebug into pry is quite a hack. They don't often play well together. Haven't used watch before so alas cannot help with this one. Maybe just email the author of byebug? – akuhn Jan 23 '17 at 18:07

2 Answers2

2

Using pry-moves you can use watch variable - this will display value of variable on each step.

Daniel Garmoshka
  • 5,849
  • 39
  • 40
1

You should be able to write a plugin that just shows the expressions after evaluating if that's exactly what you want. Pry plugins

Which you could do something simple like

Pry.hooks.add_hook(:after_eval, "reporter") do |output, binding, pry|
  $watch ||= [] 
  $watch.each {|block| block.call} 
end

$watch = [-> { puts "hello"}] 

Or something along the lines of that, would report "hello" after each new evaluation. (this is untested however, currently on mobile)