Pit Capitain
2/19/2007 6:28:00 PM
Bharat Ruparel schrieb:
> I have a side question. I am not sure when to use:
>
> 1. load
> 2. require
> 3. include
>
> it irb. Can someone give a simple set of guidelines for that?
Bharat, in addition to what Aur said, let me explain it again:
#require looks for a *file* in the Ruby load path and executes it, if it
hasn't done so already. This is the normal way to load libraries.
#load is rarely used, as Aur said. The main difference to #require is
that the file is executed everytime the #load method is called, not only
the first time.
The files executed with #require and #load normally define or extend
classes and modules.
#include allows you to include the methods of *modules* into your
current class. Often the included modules come from previously required
files, so you often see a sequence like this:
require <name-of-file>
class MyClass
include <module-defined-in-file-loaded-above>
end
Regards,
Pit