From: Brian Candler Date: 2009-06-07T01:54:21+09:00 Subject: Re: code organization Li Chen wrote: > What are the differences bewteen the following code organization? > What situations are preferred by each one? In code 1, module A is just acting as a namespace, so that you have two classes, A::B and A::C. This is useful to ensure that your class names don't stomp on anyone else's use of the same names. All you have to do is ensure name A is unique. Code 2 doesn't run as it stands, so you need to rewrite as: module A; end class B include module A end class C include module A end In this case, instance methods defined in module A are available in both class B and class C. This is almost the same as subclassing B and C from class A. B and C also get access to any constants defined in the A namespace, without needing the A:: prefix. So in summary: they achieve two completely different ends (namespace separation, and method sharing, respectively) -- Posted via http://www.ruby-forum.com/.