我现在有这个脚本.
def r(this)
require this
puts "#{this} is now loaded."
rescue LoadError
puts "The gem '#{this}' is missing."
puts "Should I install it? [y/n]"
data = gets
if data =~ /yes|y/i
puts "Installing #{this}, hold on."
if `gem install #{this}` =~ /Successfully/i
load this
end
else
puts "Okey, goodbye."
end
end
Run Code Online (Sandbox Code Playgroud)
这使得可以动态地需要库.像这样:r "haml".
问题是我无法在安装后加载gem.使用load this或load File.expand_path("~/.irbrc")不工作.
这是一个例子.
>> r "absolutize"
The gem 'absolutize' is missing.
Should I install it? [y/n]
y
Installing absolutize, hold on
LoadError: no such file to load -- absolutize
>> require "absolutize"
LoadError: no such file to load -- absolutize
>> exit
$ irb
>> require "absolutize"
=> true
Run Code Online (Sandbox Code Playgroud)
有没有办法在飞行中重新加载rubygems或irb?