britg
britg

Reputation: 225

Is there a graceful way to refactor a namespace collision with Ruby/Rails gems?

I would like to use the Ruby gem Turn, but it currently collides with a model (ActiveRecord) I have called 'Turn'. The end result is that my test output is borked.

I realize I can simply refactor my model, but I'm wondering if there's a graceful way I can namespace the gem without having to touch my model.

Any suggestions?

Upvotes: 3

Views: 740

Answers (1)

molf
molf

Reputation: 74945

Unfortunately there's no way to influence which modules (namespaces) a gem will use. Files that are required by Ruby will always be evaluated in the global scope.

It's best practice for gem authors to use a module with the same name of the gem, so usually you know what to expect when you install a gem.

Apart from not using Turn, the only solutions are to change your model's name or place it inside a namespace.

Upvotes: 4

Related Questions