SQLTerminal.app
now available

XPath.app
now available
Want fresh tech tips in your inbox?

Ruby Reload! Method in Non Rails IRB Sessions

       

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 w/ #console #development environments #irb #rc files #rubyruby

Apps I've Built

XPath Expression Editor
Practice and improve your XPath skills with XPath Editor
Click to buy on the App Store
Photo Location Changer
Easily change the location on your photos and videos
Click here for more info about the app
Photo Date Changer
Easily change the dates and times on your photos and videos
Click here for more info about the app
VocabReminder
English dictionary with notifications so you won't forget what you're studying!
Click here for more info about the app
VocabQuiz
The app that quizzes and scores you on your vocabulary!
Click here for more info about the app