autorequire

E

eastcoastcoder

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?
 
B

benjohn

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,667
Latest member
DaniloB294

Latest Threads

Top