rubybundlerprybinding.pry

Ruby (bundler) How to automatically require Pry


Given a Gemfile containing:

source 'https://rubygems.org'

gem 'pry'

And a ruby file containing:

require 'bundler/setup'

# NOT using this line:
# require 'pry'

binding.pry

I am getting this error:

enter code hereundefined method pry' for #<Binding:0x00007f846f053bb0> (NoMethodError)

I know I can easily add require 'pry' in my file, but I really dont want to do that whenever I debug a file.

Also, I would intuitively believe that bundler/setup would autorequire my rubygems defined in the Gemfile.

Can you explain how I can autorequire the file in my Gemfile?


Solution

  • The trick is to use Bundler.require(:default) after require 'bundler/setup' - since the latter just sets up the load path. See http://bundler.io/v1.16/guides/bundler_setup.html.