How to require for the second time

sawa picture sawa · Apr 24, 2012 · Viewed 8.7k times · Source

Is there a way to force require-ing of a file for the second time?

I am writing a library that is located in a path for Ruby. I am editing the file while doing a simple test of it in IRB.

Each time I make a change to the file, I want to reload it without ending the IRB session. Using load requires typing the whole path to the file each time, and restarting IRB each time requires me to type all the other variable settings required for the simple test.

I just want something like require but that allows loading for the second time. Is there a simple way to do it?

Answer

steenslag picture steenslag · Apr 24, 2012

load does not require (hmm) a full path. It expects a complete filename with an extension.

p load 'date.rb' #=> true
p load 'date.rb' #=> true
p load 'date'    #=> LoadError