[英]How to require a gem in .irbrc without needing to also add it to a Rails Gemfile?
I've added awesome_print to my ~/.irbrc
file like so: 我已经将awesome_print添加到
~/.irbrc
文件中,如下所示:
require 'ap'
Inside a Rails project directory, if I run irb
it loads the gem fine, because I've already installed the gem locally. 在Rails项目目录中,如果我运行
irb
,则可以很好地加载gem,因为我已经在本地安装了gem。 But if I run rails console
, it spits out this error: 但是,如果我运行
rails console
,它会吐出此错误:
cannot load such file -- ap
How can I resolve this? 我该如何解决? I am guessing that it's looking for the gem in the app's Gemfile, but I don't want to add it to the Gemfile because I don't want other developers requiring that dependency.
我猜想它正在寻找应用程序的Gemfile中的gem,但是我不想将其添加到Gemfile中,因为我不希望其他开发人员需要这种依赖。 I only want to use awesome_print on my machine.
我只想在我的机器上使用awesome_print。
I am also using rbenv, if that is of any help. 我也正在使用rbenv,如果有帮助的话。
What you need to do is 您需要做的是
# Copy the definition of the debundle! method into your ~/.irbrc
# Call 'debundle!' from IRB when you need to.
(as explained at the top of the file) (如文件顶部所述)
The text as it appears on the referred to site: 在所引用站点上显示的文本:
debundle.rb
allows you to require gems that are not in your Gemfile
when inspecting programs that are run with Bundler. debundle.rb
允许你需要不是在你的宝石Gemfile
检查了与捆扎机运行的程序时。
Use at your own risk! 使用风险自负!
Paste the code of debundle.rb and you are done! 粘贴debundle.rb的代码即可完成! A good place would be your
.irbrc
file before requiring irbtools . 一个好地方是需要irbtools的
.irbrc
文件。
The code is directly taken from pry-debundle . 该代码直接从pry-debundle获取 。 Please look there for any further information.
请在此处查找更多信息。 This repo exists to simplify debundling without using the
pry
repl. 存在此回购可简化拆分过程,而无需使用
pry
repl。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.