ConradIrwin / pry-rescue

Start a pry session whenever something goes wrong.
MIT License
852 stars 49 forks source link

More elegant solution to loading pry-rescue via pryrc? #111

Open gerrywastaken opened 6 years ago

gerrywastaken commented 6 years ago

Hi, I want pry rescue to always work no matter how pry is loaded. It would be great if I could just do something in my pryrc to activate pry rescue at runtime. The following code works but it's not very elegant. Is there a better way?

begin
  require 'pry-rescue'

  Pry.config.hooks.add_hook(:before_eval, :save_me) do |code, _pry|
    code.replace("Pry::rescue do\n\n#{code}\n\nend")
  end
rescue LoadError => err
  puts "no pry-rescue :("
end