Forum: Ruby autorequire

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
unknown (Guest)
on 2006-03-13 18:26
(Received via mailing list)
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?
unknown (Guest)
on 2006-03-14 16:17
(Received via mailing list)
> 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.
This topic is locked and can not be replied to.