Written by Sean Behan on Sun Jun 17th 2012

I love the Rails reload! function when in the console. I need it in Irb. To get it back this is what I did. If you don't already have an .irbrc file in your home directory, just create it.

vim ~/.irbrc
or textmate if you prefer
mate ~/.irbrc

Add this little snippet to it...

unless defined?(reload!)
  $files = []
  def load!(file)
    $files << file
    load file
  end
  def reload!
    $files.each { |f| load f }
  end
end

Usage : To load files in irb just use the method we defined in the .irbrc file "load!" notice the bang "!". I don't want to overwrite the actual load method. This load! method will just put the file in an array before loading it, so when running reload! it will iterate over this collection and load them again with whatever changes have since taken place. The unless conditional is so that you don't overwrite the reload! method if you're actually in the rails console.


Tagged with..
#console #development environments #irb #rc files #ruby #ruby

Just finishing up brewing up some fresh ground comments...