From: matt@... (matt neuburg) Date: 2009-06-07T04:30:07+09:00 Subject: Re: code organization Li Chen wrote: > Hi all, > > What are the differences bewteen the following code organization? > What situations are preferred by each one? > > Thanks, > > Li > > #######code 1############# > module A > class B end > class C end > end > > > > #######code 2############# > class B > include module A > end > > class C > include module A > end They are totally different, and they illustrate the two main purposes of a module. Neither is legal as you have it so I will change the code to make it legal. ##### 1 ###### module A class B end end A::B.new A is a namespace, so you must say A::B from outside module A to refer to B. ##### 2 ##### module A def hello p "howdy" end end class B include A end B.new.hello Module A's instance methods are copied into class B as instance methods ("mixin"). m. -- matt neuburg, phd = matt@tidbits.com, http://www.tidbits.com/matt/ Leopard - http://www.takecontrolbooks.com/leopard-customizing.html AppleScript - http://www.amazon.com/gp/product/0596102119 Read TidBITS! It's free and smart. http://www.tidbits.com