From: Mike Papper Date: 2009-12-05T09:37:54+09:00 Subject: Re: Use of extend from within a Class Hi and thanks, please note that I am extending the module from within my class. the problem is exactly with the call of the form self.class... concerning what you said about self.class (inside the module): def mb self.class.cee I used this in my example because the rails module that I am extending does this. It is included using the method named 'helper' and that must do special things to make it work in the context of rails+controller. What I really want to do is use url_for of the rails' ActionController::UrlWriter. as it happens, that module does have ClassMethods and within there a method that calls self.class (which fails when I extend the module). Mike ---- Jesús Gabriel y Galán wrote: > On Sat, Dec 5, 2009 at 12:37 AM, Mike Papper > wrote: >> I would like to include a module into a 'static' class - such that all >> the modules methods are class methods. > > One basic way to do this is to have the class extend the module: > > irb(main):017:0> module Z > irb(main):018:1> def test; "testZ"; end > irb(main):019:1> end > => nil > irb(main):020:0> class C > irb(main):021:1> extend Z > irb(main):022:1> end > => C > irb(main):023:0> C.test > => "testZ" > > >> >> �def mb >> � �self.class.cee > > This is wrong. self.class is Class, and the Class class doesn't have a > method "cee". > >> �end >> >> �module ClassMethods >> � �attr_writer :cee >> >> � �def cee >> � � �puts "CCCCCCCCCCCCC" >> � �end >> �end >> end > -- Posted via http://www.ruby-forum.com/.