Ruby - load vs require


Ruby lets you load a file using the load method.

In most respects, require and load can be regarded as interchangeable.

load can take an optional second argument, if this is true, loads and executes the code as an unnamed or anonymous module:

load( "testmod.rb", true)

When the second argument is true, the file loaded does not introduce the new namespace into the main program.

In that case, the Module methods, constants, and instance methods will not be available to your code:

When the second argument to load is false or when there is no second argument, you will have access to modules in the loaded file:

You must enter the full filename with load.

require loads a file once only even if your code requires that file many times.

load causes the specified file to be reloaded each time load is called.

Related Topic