From: "Jakub Pavlík jn." Date: 2008-10-03T02:36:00+09:00 Subject: Re: Problem extending (adding methods) to class Class defined inside a module behaves exactly the same as if she was defined 'outside' - it isn't 'static' in any way. (Following notes may either help you or not - I haven't understood totally where exactly your problem is.) If you want to extend class ClassC defined inside module ModuleM , you can either write module ModuleM class ClassC # add new methods here end end or class ModuleM::ClassC # add new methods here end Similarly if you want to subclass ClassC, you can do it inside ModuleM module ModuleM class ClassD < ClassC # blah blah end end or outside: class ClassD < ModuleM::ClassC # blah blah end Sorry if I didn't understand you at all... > Lex Williams wrote: > > Nit Khair wrote: > >> Nit Khair wrote: > >>> I am trying to extend a class developed by someone else (its from the > >>> ncurses-ruby lib). I need to add some fields and methods to it. > >>> > >> > >> On further thought I am wondering if being inside a module makes that > >> class different. Like some sort of static or factory class. Nothing > >> coming up on google on "module classes" or classes within modules. > >> > >> Could someone explain this or point me to a link. I read that modules > >> cannot be instantiated or subclasses - fine. What of classes declared in > >> them ? > > > > why don't you take advantage of open classes ? > > > > you can write this : > > > > class MyClass > > attr_accessor :myfield > > end > > > > and then you can access myfield using any instance of that class . The > > same goes with methods . > > > > If you write : > > > > class MyClass > > def my_new_method > > #some logic here > > end > > end > > > > then , all your objects will have that method . > > Are you by any chance saying the same thing i have done above, when i > copied the Module Class thing from the original source and added my > method and data to it ? > > However, this much is working, but i need a heirarchy. I am unable to > extend this and add methods to it. > > If the original class was declared as: > > >Module MyClass > > class MYCLASS > > attr_accessor :myfield > > end > >end > > I can copy this, and add: > attr_accessor :newfield > This is okay. > > But when i do: > > class AnotherClass < MYCLASS > attr_accessor :anotherfield > end > > then i get a NoMethodError pointing to MyClass::MYCLASS. I get no error > when instantiating AnotherClass, only when i access the method added. > > I need a heirarchy of classes under Ncurses::FORM. > > -- > Posted via http://www.ruby-forum.com/. -- Zat�mco velbloud dvouhrb� m� hrby dva, Dromed�r m� jen jeden.