---
title: "Enabling Pry with reload"
author: "夜鸣猪"
date: "2012-10-23T02:05:18Z"
tags: []
categories: ["编程语言"]
slug: "enabling-pry-with-reload"
draft: false
lastmod: "2012-10-23T02:05:18Z"
id: 1703401
url: "https://hlee.iteye.com/blog/1703401"
---

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](https://github.com/rails/rails/pull/3509)