From: Eero Saynatkari Date: 2006-08-11T07:27:04+09:00 Subject: Re: Modules -> do I have is straight? Simon Harrison wrote: > A related question: is this why many libraries nest classes inside a > main module? > > i.e. > > module DataBase > class Table > class Column > ... > end > > class Row > ... > end > end > end > > Are their any good explanations of designing programs using this > convention? This is apart from modules' normal usage as mixins. The module is just there to provide a structure or a namespace for the code, similar to Java's packages. When a programmer #requires your file, they must refer to your class as DataBase::Table which is useful for all the normal reasons. One interesting thing arising from modules in fact being Modules and the top-level execution context being an Object is that you can reduce namespaces. In the event that a programmer does not want to use your DataBase namespace everywhere, they can #include it just like any other Module and thereby mixing in its contents with normal mixin semantics: module Foo Class Bar end end Bar.new # Error Foo::Bar.new # OK include Bar Bar.new # Now OK also! -- Posted via http://www.ruby-forum.com/.