ruby-on-railsrubyirb

How to automatically set an IRB configuration across all environments for a specific rails app?


I'd like to set an IRB configuration across an app (all environments, including production) so I don't have to run it every time I use the rails console. The specific configuration isn't that important, but it's:

IRB.conf[:USE_PAGER] = false 

What I've tried

I thought it would be as simple as:

# config/initializers/console.rb
Rails.application.console do
  IRB.conf[:USE_PAGER] = false
end

but when I open the rails console

IRB.conf[:USE_PAGER]
# => true

confirming that it hasn't set (or was set but was overridden).

Note


Solution

  • You can add .irbrc into your project. There are multiple locations that a configuration file can be loaded from, including the current directory, which can be your project. Although, the docs say "the first file found", all the files found will be loaded:

    The path to the configuration file is the first found among:

    • The value of variable $IRBRC, if defined.
    • The value of variable $XDG_CONFIG_HOME/irb/irbrc, if defined.
    • File $HOME/.irbrc, if it exists.
    • File $HOME/.config/irb/irbrc, if it exists.
    • File .irbrc in the current directory, if it exists.
    • File irb.rc in the current directory, if it exists.
    • File _irbrc in the current directory, if it exists.
    • File $irbrc in the current directory, if it exists.

    https://docs.ruby-lang.org/en/master/IRB.html#module-IRB-label-Configuration+File