/ ruby

Disable pry and exit debugger without killing the main program in Ruby

You ever ran into a situation where you had a huge loop running and you put a binding.pry within that loop for debugging and wondered how the hell you would exit the debugger?

The answer is simple

disable-pry is your saviour.!

via GIPHY

This has got its downside though, this will disable any further invocations of the pry again.

Under the hood its disabling the whole pry and setting ENV['DISABLE_PRY'] = true

To re-enable pry for any further debugging you will have to clear the ENV var by ENV['DISABLE_PRY'] = nil

I have defined a helper method enable_pry with the following inside my .pryrc for my convenience.

def enable_pry
  ENV['DISABLE_PRY'] = nil
end

Credits where its due: https://stackoverflow.com/questions/8015531/how-do-i-step-out-of-a-loop-with-ruby-pry

Happy coding.!!

Manu S Ajith

Manu S Ajith

Tech Entrepreneur, dating Elixir, in long-term ❤️ w/ Ruby, had multiple one night stands w/ Go. Into functional paradigms DDD/CQRS/EventSourcing architecture these days. @manusajith on the interwebs

Read More