From: "David A. Black" Date: 2008-06-01T09:16:00+09:00 Subject: Re: Class Module Hi -- On Sun, 1 Jun 2008, Wesley Silva wrote: > Thanks a lot David! > > I would like to make another question please...:) > > If i just change Modules's name for Father for example: > > class Father > @@docs = {} > def doc(str) > @@docs[self.name] = self.name + ":\n" + str.gsub(/^\s+/, '') > end > def Father::show_doc(aClass) > aClass = aClass.name if aClass.class <= Module > @@docs[aClass] || "No documentation for #{aClass}" > end > end > class Example doc("This is a sample documentation string") > end > > puts Father::show_doc(Example) > > Produces: > > undefined method `doc' for Example:Class (NoMethodError) > > Can you tell why? :) doc is an instance method of Father, and Example is not an instance of Father (it's an instance of Class). So you can't call doc on Example. David -- Rails training from David A. Black and Ruby Power and Light: INTRO TO RAILS June 9-12 Berlin ADVANCING WITH RAILS June 16-19 Berlin See http://www.rubypal.com for details and updates!