为了使用 rubyzip,我安装了 gems:
gem install --local rubyzip-1.1.7.gem
gem install --local zip-zip-0.3.gem
在我的代码中,我使用 require 方法调用 gem:
require 'zip/zip'
require 'zip/filesystem'
我想使用 require 直接从我的机器上的位置加载 gem。
我想要这样的东西:
require 'path_to_my_zip_gem'
path_to_my zip_gem 包含 gem 文件的位置
最佳答案
基本上,这是因为 require
方法从 $:
或 $LOAD_PATH
中列出的路径按名称加载文件
"If the filename does not resolve to an absolute path, it will be searched for in the directories listed in $LOAD_PATH ($:)."
如果您想从“本地”路径获取 gem,则 require_relative
方法可能会有所帮助,因为您可以指定相对于所需文件路径的路径。更多详情请查看官方文档:
http://ruby-doc.org/core-2.2.2/Kernel.html#method-i-require_relative
关于ruby - 如何直接从路径中获取 Ruby gem?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30187990/