Two gems share same require?

2019-04-08 05:41发布

问题:

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