How do I step out of a loop with Ruby Pry?

前端 未结 9 1182
醉话见心
醉话见心 2020-12-22 15:11

I\'m using Pry with my Rails application. I set binding.pry inside a loop in my model to try and debug a problem. For example:

(1..100).each do          


        
9条回答
  •  心在旅途
    2020-12-22 15:50

    Based on the two previous answers above:

    • https://stackoverflow.com/a/21735420/3137698
    • https://stackoverflow.com/a/24945487/3137698

    Thank you guys! Your advices have helped me really a lot!

    I just want to share a simple stupid trick, that I personally use to don't worry about the DISABLE_PRY environment variable all the time. Add this callback to the base controller ApplicationController of your project permanently. It would automatically re-enable PRY every time the disable-pry is called:

    # app/controllers/application_controller.rb
    class ApplicationController < ActionController::Base
      before_action :reenable_pry
    
      private
    
      def reenable_pry
        ENV['DISABLE_PRY'] = nil
      end
    end
    

提交回复
热议问题