gpt4 book ai didi

ruby - 在 irb 中重新加载 ruby​​gems?

转载 作者:数据小太阳 更新时间:2023-10-29 06:49:36 30 4
gpt4 key购买 nike

我现在有这个脚本。

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

这使得即时请求库成为可能。像这样:r "haml"

问题是 gem 安装后无法加载。使用 load thisload 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

有没有办法即时重新加载 ruby​​gems 或 irb?

最佳答案

我没试过,但我想你可能正在寻找 Gem.clear_paths

Reset the dir and path values. The next time dir or path is requested, the values will be calculated from scratch. This is mainly used by the unit tests to provide test isolation.

关于ruby - 在 irb 中重新加载 ruby​​gems?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5807015/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com