So far, I’ve mixed in modules that have been defined within a single source file. Often it is more useful to define modules in separate files and mix them in as needed. The first thing you have to do in order to use code from another file is to load that file using the
require method, like this:
require( "./testmod.rb" )
Optionally, you may omit the file extension:
require( "./testmod" ) # this works too
If no path is given, the required file must be in the current directory, on the search path, or in a folder listed in the predefined array variable
$:. You can add a directory to this array variable using the usual array-append method,
<<, in this way:
$: << "C:/mydir"
The global variable,
$: (a dollar ...