欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Enabling Pry with reload

程序员文章站 2022-07-15 11:50:08
...

For anyone coming to this question recently: the answer has changed in Rails 3.2, because they've changed how they implement reload! Where in earlier version the irb commands were added as methods to Object, now they are added to IRB::ExtendCommandBundle to avoid polluting the global namespace.

What I do now is (1) in development.rb

silence_warnings do
  begin
    require 'pry'
    IRB = Pry
    module Pry::RailsCommands ;end
    IRB::ExtendCommandBundle = Pry::RailsCommands
  rescue LoadError
  end
end

and (2) in .pryrc

if Kernel.const_defined?("Rails") then
  require File.join(Rails.root,"config","environment")
  require 'rails/console/app'
  require 'rails/console/helpers'
  Pry::RailsCommands.instance_methods.each do |name| 
    Pry::Commands.command name.to_s do 
      Class.new.extend(Pry::RailsCommands).send(name)
    end
  end
end

Here's the link to the Rails pull request where the change was introduced -https://github.com/rails/rails/pull/3509

相关标签: rails pry