ruby-on-railsrubyirb

How can I automatically set an IRB configuration across all environments for a specific Ruby on Rails application?


I'd like to set an IRB configuration across an application (all environments, including production), so I don't have to run it every time I use the Ruby on 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 Ruby on 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 documentation says "the first file found", all the files found will be loaded:

    IRB searches for a configuration file in the following order:

    • $IRBRC
    • $XDG_CONFIG_HOME/irb/irbrc
    • $HOME/.irbrc
    • $HOME/.config/irb/irbrc
    • .irbrc in the current directory
    • irb.rc in the current directory
    • _irbrc in the current directory
    • $irbrc in the current directory

    https://ruby.github.io/irb/Configurations_md.html#label-Configuration+File+Path+Resolution