~/.irbrc not executed when starting irb or script/console
Asked Answered
V

6

10

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 #
Volute answered 24/4, 2010 at 10:1 Comment(0)
N
8

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

Nonagon answered 24/4, 2010 at 15:56 Comment(0)
B
20

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).

Beanpole answered 1/10, 2011 at 4:46 Comment(1)
Yupp, this definitely helped me debug my situation and lead to a fix. (I'm just puzzled that IRB didn't complain when loading irb when a gem was missing.)Wend
L
13

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.

Lazos answered 13/2, 2017 at 14:52 Comment(0)
N
8

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

Nonagon answered 24/4, 2010 at 15:56 Comment(0)
A
7

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

Alitaalitha answered 27/7, 2010 at 5:55 Comment(1)
Had the same problem. In particular, if there are any require statements at the top, and they don't work because of the bundler environment, the whole .irbrc will be ignored silently. Solution: begin / rescue Exception / end blocks around everything that could fail.Eraser
T
1

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.

Tiebout answered 3/3, 2011 at 20:50 Comment(0)
S
0

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.

Sirkin answered 20/9, 2023 at 14:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.