【问题标题】:How to resolve same module name from multiple gems?如何从多个 gem 中解析相同的模块名称?
【发布时间】:2015-08-22 10:13:06
【问题描述】:

我安装了两个名为 libarchivelibarchive-ruby 的 gem。两者都需要require archive 行。但问题是,当我想使用来自libarchive-ruby 的存档库时,我不能。 Ruby 转到来自libarchive 的那个。

有没有办法告诉 Ruby 我想使用哪个库?我知道,我可以卸载一个,但还有其他更好的选择吗?

【问题讨论】:

标签: ruby rubygems require


【解决方案1】:

使用Bundler 管理您的依赖项:

宝石文件

source 'https://rubygems.org'

gem 'libarchive-ruby', :require => 'archive'

whatever.rb

require 'bundler/setup'
Bundler.require :default  # :default is the group name of the implicit group

# Your code

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-13
    • 2014-05-23
    • 1970-01-01
    • 2012-01-31
    • 1970-01-01
    相关资源
    最近更新 更多