【问题标题】:How to require a gem in .irbrc without needing to also add it to a Rails Gemfile?如何在.irbrc 中需要一个gem,而无需将其添加到Rails Gemfile?
【发布时间】:2013-07-19 10:22:03
【问题描述】:

我已将awesome_print 添加到我的~/.irbrc 文件中,如下所示:

require 'ap'

在 Rails 项目目录中,如果我运行 irb,它会很好地加载 gem,因为我已经在本地安装了 gem。但是如果我运行rails console,它会吐出这个错误:

cannot load such file -- ap

我该如何解决这个问题?我猜它正在应用程序的 Gemfile 中寻找 gem,但我不想将它添加到 Gemfile,因为我不希望其他开发人员需要该依赖项。我只想在我的机器上使用 awesome_print。

如果有帮助的话,我也在使用 rbenv。

【问题讨论】:

    标签: ruby-on-rails ruby unix gem irb


    【解决方案1】:

    有这个trick

    你需要做的是

    # Copy the definition of the debundle! method into your ~/.irbrc
    # Call 'debundle!' from IRB when you need to.
    

    (如文件顶部所述)

    显示在所指网站上的文本:


    debundle.rb 允许您在检查时要求不在您的Gemfile 中的宝石 使用 Bundler 运行的程序。

    使用风险自负!

    粘贴 debundle.rb 的代码,大功告成!一个好地方是你的.irbrc 文件 在要求irbtools之前。

    代码直接取自pry-debundle。 请在此处查看更多信息。这个 repo 的存在是为了简化拆分 不使用pry repl。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-18
      • 2011-06-13
      • 2020-01-17
      • 2021-10-28
      • 2023-03-07
      • 1970-01-01
      • 2012-11-26
      • 2013-10-16
      相关资源
      最近更新 更多