By gst
via rubyfleebie.com
Published: Sep 11 2007 / 12:49
In the first part, we learned that a module was a namespace, a way to regroup similar things to help us organize our application better and to avoid name clashes. It was rather easy to understand because we didn’t speak about the true power that resides in modules.
Other than a namespace, what is a module?
A module is like a class with 3 key differences :
1. It is not a class (this one is the killer)
2. It cannot be instantiated (i.e. you cannot do x = MyModule.new)
3. It can be mixed in a class to enhance its possibilities
And here is the tricky part : Although a module cannot have instances, it can still have instance methods. How is it possible? Well, you guessed it : those instance methods will become the instance methods of the client (the class).
Add your comment
Voters For This Link (15)
-
gst -
rick -
zis -
daniel -
dansim -
lupideloop -
tarellel -
rob_dimarco -
kdenehy -
yopmail22 -
TiSHuS -
ashayh -
michaelklishin.myopenid.com -
michael@novemberain.com -
davneter