Two gems share same require?

旧街凉风 提交于 2019-12-06 01:42:08

问题


When I call:

require 'retryable' 

These two gems clash:

  • https://github.com/robertsosinski/retryable
  • https://github.com/carlo/retryable

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'


回答1:


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


来源:https://stackoverflow.com/questions/20054133/two-gems-share-same-require

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!