Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 #
like image 801
Patrick Klingemann Avatar asked Apr 24 '10 10:04

Patrick Klingemann


2 Answers

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.

like image 188
Nathan Long Avatar answered Sep 23 '22 23:09

Nathan Long


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

like image 30
Stian Håklev Avatar answered Sep 23 '22 23:09

Stian Håklev