Skip to content

Instantly share code, notes, and snippets.

@petekinnecom
Created May 4, 2018 21:43
Show Gist options
  • Select an option

  • Save petekinnecom/4c39ae1dddc28556747a6cda58d5153b to your computer and use it in GitHub Desktop.

Select an option

Save petekinnecom/4c39ae1dddc28556747a6cda58d5153b to your computer and use it in GitHub Desktop.
# If you'd like to be able to require the pry gem even though it isn't in your Gemfile,
# you can use this file. I suggest putting it at `~/pry.rb`, then instead of calling
# `require 'pry'; binding.pry` you can call `require '~/pry'; binding.pry
class BundlerBreakout
def initialize(libname)
@libname = libname
end
def load
require @libname
rescue LoadError
$LOAD_PATH.unshift(*libs)
require @libname
end
private
def libs
clean_env do
out = <<~`SH`
ruby <<RUBY
pre = \\$LOAD_PATH.dup
require '#{@libname}'
puts \\$LOAD_PATH - pre
RUBY
SH
out.split("\n")
end
end
def clean_env(&block)
if defined?(Bundler)
Bundler.with_clean_env(&block)
else
block.call
end
end
end
BundlerBreakout.new('pry').load
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment