开发者

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 t开发者_Go百科hat 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜