当尝试加载已经加载宝石的ruby脚本执行中途安装的gem时,无法找到已安装的gem。我查看了Gem::Specification
的源代码,并在阅读器上查找了all
类变量,对已缓存的gemspec
文件进行了扫描。
使用Gem::Specification.all = nil
重置此变量有效,但附带此评论:
##
# Sets the known specs to +specs+. Not guaranteed to work for you in
# the future. Use at your own risk. Caveat emptor. Doomy doom doom.
# Etc etc.
#
#--
# Makes +specs+ the known specs
# Listen, time is a river
# Winter comes, code breaks
#
# -- wilsonb
def self.all= specs
@@all = specs
end
我想知道是否有更好的方式。