Added force_require for binding.irb

When we make irb to bundled gems, binding.irb with bundle exec is not
working without irb declaration of Gemfile.

This force_require makes to load irb without Gemfile.
This commit is contained in:
Hiroshi SHIBATA 2024-09-06 13:06:56 +09:00
Родитель e43d701f09
Коммит 69d0e690bb
1 изменённых файлов: 19 добавлений и 1 удалений

Просмотреть файл

@ -1,12 +1,30 @@
class Binding
# :nodoc:
def irb
begin
require 'irb'
rescue LoadError
force_require "irb" if defined?(Bundler)
end
irb
end
# suppress redefinition warning
alias irb irb # :nodoc:
private def force_require(gem)
gemspecs = (Gem::Specification.dirs + [Gem.default_specifications_dir]).map{|d|
Dir.glob("#{d}/#{gem}*.gemspec").reverse
}.flatten
if gemspecs.empty?
false
else
gemspec = Gem::Specification.load(gemspecs[0])
gemspec.dependencies.each{|dep| force_require dep.name }
gemspec.activate
require gem.gsub("-", "/")
end
end
end
module Kernel