Disabling Pry in Non Dev Environments

You would normally only include the pry gem in your development environment. As a result, if you leave a pry binding in place outside of development, the code breaks when executed. Of course you shouldn't leave bindings in your source code unless you fully intend to use them, but you can nullify them just in case they get overlooked somehow. Aim for perfection, but plan for errors.

One way to disable pry bindings is by prepending a module to the Binding class that returns nil from a pry method call in all environments except development.

# placed in config/initializers/utilities.rb
unless Rails.env.development?
module BindingExtensions
def pry
class Binding
prepend BindingExtensions

In order to make this module available throughout the project, I created a generic utilities initializer (config/initializers/utilities.rb) and added it there.
Picked by MJ
Jul. 08 2016