From: Nit Khair Date: 2008-10-03T03:30:29+09:00 Subject: Re: Problem extending (adding methods) to class Jakub Pavl鱈k jn. wrote: > module ModuleM > class ClassC > # add new methods here > end > end > Thanks, this worked fine. > > Similarly if you want to subclass ClassC, you can do it inside ModuleM > > module ModuleM > class ClassD < ClassC > # blah blah > end > end > Not tried this. > or outside: > > class ClassD < ModuleM::ClassC > # blah blah > end > THIS did not work. I got NoMethodErrors trying this out. I spent many hours checking and trying to see if some other error was happening. I needed: class AForm < Ncurses::FORM class BForm < AForm and so on. So finally, i removed the < clause abd created an instance in the initializer. And used "method_missing" to call methods of that instance. This is working perfectly, i can keep subclassing ... However, i still want to understand what i did wrong. or what i am not understanding about classes within modules. --- Why create classes within modules ? Is it only a namespace issue - to avoid clashes with other classes. Is it like java's package? Should we always create modules and packages inside them in a project with many classes ? Currently I have only one module with common stuff and a heriarchy of classes under no module. -- Posted via http://www.ruby-forum.com/.