启动 irb 或脚本/控制台时不执行 ~/.irbrc

发布于 2024-08-29 22:48:09 字数 263 浏览 9 评论 0原文

这是我尝试过的:

1. gem install awesome_print
2. echo "require 'ap'" >> ~/.irbrc
3. chmod u+x ~/.irbrc
4. script/console
5. ap { :test => 'value' }

结果:

NameError: undefined local variable or method `ap' for #

Here's what I've tried:

1. gem install awesome_print
2. echo "require 'ap'" >> ~/.irbrc
3. chmod u+x ~/.irbrc
4. script/console
5. ap { :test => 'value' }

Result:

NameError: undefined local variable or method `ap' for #

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

半夏半凉 2024-09-05 22:48:09

要检查 .irbrc 中的哪些内容失败,只需将 .irbrc 作为普通 Ruby 脚本 (ruby ~/.irbrc) 执行,Ruby 将告诉您哪一行失败。它可能会抱怨 IRB 模块丢失,只需要在脚本中使用“irb”(您只在测试时需要它,而不是在实际运行 IRB 时需要)。

To check what in .irbrc is failing, just execute .irbrc as a normal Ruby script (ruby ~/.irbrc), and Ruby will tell you which line fails. It might complain that IRB module is missing, just require 'irb' in the script (you only need this when testing it, not when actually running IRB).

心的位置 2024-09-05 22:48:09

你的 Rails 控制台可能正在使用 Pry

根据 ~/.irbrc 必须无效的建议,我将我的简化为单个 puts "hi",尽管它在我运行了irb,但当我运行rails console时却没有。

我终于注意到提示符是pry(main)。事实证明,这个 Rails 项目是使用 pry-rails gem 设置的,所以这就是控制台所使用的。自定义 .pryrc 可以解决问题。

Your Rails Console May Be Using Pry

Based on the suggestions that ~/.irbrc must be invalid, I reduced mine to a single puts "hi", and although it output when I ran irb, it did not when I ran rails console.

I finally noticed that the prompt was pry(main). It turned out that this Rails project is set up with the pry-rails gem, so that's what the console uses. Customizing .pryrc does the trick.

仅此而已 2024-09-05 22:48:09

将“require 'rubygems'”添加到我的 ~/.irbrc 文件似乎可以解决问题。

Adding "require 'rubygems'" to my ~/.irbrc file seemed to do the trick.

Oo萌小芽oO 2024-09-05 22:48:09

就我而言,它是“如果你的 ~/.irbrc 无效,它将失败
默默地。”——来自谷歌搜索
- 发现并修复了 ~/.irbrc 中的错误,一切正常

In my case it was "If your ~/.irbrc is invalid, it will fail
silently." - from Google search
- found and fixed errors in ~/.irbrc, all working fine

九公里浅绿 2024-09-05 22:48:09

您需要添加 require 'rubygems' 正如 jdeseno 所写。

如果您使用 Rails3 并使用 Bundler,则还需要在 Gemfile(在 :development 组中)中指定“awesome_print”gem 才能使其正常工作。

You need to add require 'rubygems' as jdeseno wrote.

If you are on Rails3 and use Bundler, you also need to specify the 'awesome_print' gem in the Gemfile too (in the :development group) for it to work.

飘逸的'云 2024-09-05 22:48:09

请检查应用程序是否使用 Pry 或 Debug。对于前者,编辑 .pryrc;后者使用 .irbrc。

您可以在存储库目录中编辑 .pryrc。扫描本地目录和 $HOME 中的点文件。

Do check whether the application is using Pry or Debug. For the former, edit .pryrc; the latter uses .irbrc.

You can edit .pryrc in your repository directory. The local directory and $HOME is scanned for the dot file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文