Link Details

Link 40395 thumbnail
User 217101 avatar

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).
  • 15
  • 0
  • 1047
  • 306

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.