Autorequire


#1

I know Rails uses some const_missing magic to automatically require
modules and classes based on their names (ie RealEstate::Location.new
–> autorequires ‘real_estate/location’).

Any advice on how to use this for general ruby programming?

Any reason not to?


#2

I know Rails uses some const_missing magic to automatically require
modules and classes based on their names (ie RealEstate::Location.new
–> autorequires ‘real_estate/location’).

Any advice on how to use this for general ruby programming?

I think you want Kernel::autoload( module_name, module_path ), and also
Module::autoload. On the first use of module_name, it’ll be loaded from
the path ready for use. It’s useful for only loading something in at the
point where it is needed, and avoiding loading it at all if it’s never
needed.