我已经看到在安装 gem 时如何安装依赖的 gem,但是我该怎么做呢?
我是 ruby 新手,遵循 创建 gem 的教程,以及 如何使用捆绑器。但我多次看到安装 gem 时会自动安装依赖的 gem...我该怎么做?我尝试将 Gemfile 与 gem 包捆绑在一起,但没有执行任何操作。还尝试在我的脚本中要求“bundler/setup”,但这也不起作用。我该怎么办?
I a new to ruby, have followed a tutorial to create a gem, and how to use bundler. But I have seen many times when installing a gem that dependant gems are automatically installed ... how do I do that? I have tried bundling my Gemfile with the gem package which did nothing. Have also tried requiring "bundler/setup" in my script, which did not work either. How do I go about this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您在 gemspec 中指定依赖项是正确的。您应该指定运行时和开发依赖项。
警告:如果您正在构建 gem 并使用
bundler
,您的 Gemfile 应该仅包含以下内容以了解更多信息,特别是如果这是您第一次开发 gem你应该看看 yehuda 的 关于该主题的帖子。另请查看 docs
基本思想是,捆绑程序只会将 gem 安装为由您的 gemspec 指定。这样,您只需将依赖项保留在一处。这还可以确保捆绑程序不使用锁定文件,这对于确保与依赖的 gem 保持兼容非常重要。
You are correct you specify dependencies in the gemspec. You should specify both runtime and development dependencies.
One word of caution: If you are building a gem and using
bundler
, your Gemfile should only contain the followingFor more info, especially if this is your first time developing a gem you should take a look at yehuda's post on the subject. Also take a look at the docs
The basic idea, is that bundler will only install gems as specified by your gemspec. This way you only keep your dependencies in one place. This also ensures that bundler isn't using a lockfile, which can be important to ensure you remain compatible with dependent gems.
很简单:
只需在 gemspec 中指定依赖项。
Its easy:
Just specify the dependencies in the gemspec.