On Tue, Sep 09, 2003 at 06:01:59PM +0900, Tobias Peters wrote: > > Unfortunately there's nothing tying the method to the method_info > > without telling it. > > Yes there is. method_added is what you need. See: > > >>>>>>>>test_method_added.rb>>>>>>>> [...] > <<<<<<<<<<<<test_method_added.rb<<<<<<<<<<< > > $ ruby test_method_added > [#<Method_Doc:0x4013f34c > @method_name=:initialize, > @klass=Example, > @data="\t\tThis does some serious init work\n">] > > @klass info comes from Module#method_doc, @method_name info comes from > Module#method_added > > > In a few cases, I've used this in subclasses > > without any method redefinition, just to make the wordking more > > appropriate. (This is used to generate various forms.) > > I cannot follow. I think he meant the method you suggest wouldn't work if the method is not redefined, but it makes sense to expand it as follows METHOD_DOCS = [] class Method_Doc def initialize(data, klass) @data = data @klass = klass METHOD_DOCS << self end attr_accessor :method_name attr_reader :data, :klass end class Module def method_doc(data, method = nil) if method d = Method_Doc.new data, self d.method_name = method @last_method_doc = nil # don't mess up else @last_method_doc = Method_Doc.new(data, self); end end alias pre_method_doc_method_added method_added def method_added(name) @last_method_doc ||= nil # get rid of warning with -w (doc = @last_method_doc) && (doc.method_name = name) @last_method_doc = nil # don't modify twice the same docs pre_method_doc_method_added(name) end end class Example method_doc <<-DOC This does some serious init work DOC def initialize(a,b) @a,@b=a,b end def foo end end class Bla < Example method_doc <<-DOC, :initialize # this breaks vim's syntax colouring :P This does some serious init work, but I explain it using a terminology more appropriate for Bla. DOC def bar # this shouldn't be documented end end p METHOD_DOCS -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com We come to bury DOS, not to praise it. -- Paul Vojta, vojta / math.berkeley.edu