两个宝石有相同的要求? [英] Two gems share same require?

查看:85
本文介绍了两个宝石有相同的要求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我打电话时:

  require'retryable'

这两个宝石冲突:



因为他们都有一个'可重试'文件,他们要求用户要求。我有兴趣使用第一颗宝石,但这并不总是会发生。



这段代码是作为我自己的宝石的一部分执行的,它必须在所有用户中可靠。



如何解决此命名冲突?

如何解决命名冲突?



编辑:澄清,这是官方回购和宝石名称实际上是不同的(retryable-rb和carlo-retryable),但他们都要求他们的用户要求lib / retryable.rb文件与 require'retryable'

解决方案

您可以使用 gem 方法

在这种情况下,您希望可重试-rb gem,而不是任何可能具有 retryable.rb 文件的其他人:

  gem'retryable-rb'#激活相关的宝石
#并将它的lib目录添加到加载路径

require'retryable'#从retryable-rb gem加载retryable.rb,因为
#现在位于加载路径


When I call:

require 'retryable' 

These two gems clash:

as they both have a 'retryable' file they ask the user to require. I'm interested in using the first gem, however this doesn't always happen.

This code is executed as a part of my own gem, and it has to be reliable across all users.

Is there a way to require specifically from a gem (as the gem names are different of course)?

How do I resolve this naming conflict?

EDIT: To clarify, this is the official repo and the gem names are actually different ("retryable-rb" and "carlo-retryable"), however they both ask their users to require the lib/retryable.rb file with require 'retryable'

解决方案

You can explicitly activate a specific gem with the gem method.

In this case you want the retryable-rb gem, and not any others that may have a retryable.rb file:

gem 'retryable-rb'   # activates the gem in question
                     # and adds its lib dir to load path

require 'retryable'  # loads retryable.rb from the retryable-rb gem, as it
                     # is now on the load path

这篇关于两个宝石有相同的要求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆