Tutorial by Examples

The Kernel#require method will load files only once (several calls to require will result in the code in that file being evaluated only once). It will search your ruby $LOAD_PATH to find the required file if the parameter is not an absolute path. Extensions like .rb, .so, .o or .dll are optional. Re...
The method Kernel#autoload registers filename to be loaded (using Kernel::require) the first time that module (which may be a String or a symbol) is accessed. autoload :MyModule, '/usr/local/lib/modules/my_module.rb' The method Kernel#autoload? returns filename to be loaded if name is registere...
When files are not available, the require family will throw a LoadError. This is an example which illustrates loading optional modules only if they exist. module TidBits @@unavailableModules = [] [ { name: 'CoreExtend', file: 'core_extend/lib/core_extend' } \ , { name: 'Fs' ...
The Kernel#load method will evaluate the code in the given file. The search path will be constructed as with require. It will re-evaluate that code on every subsequent call unlike require. There is no load_relative. load `somefile`
You can use any ruby technique to dynamically create a list of files to load. Illustration of globbing for files starting with test, loaded in alphabetical order. Dir[ "#{ __dir__ }**/test*.rb" ) ].sort.each do |source| require_relative source end

Page 1 of 1