Moduleクラスを拡張してごにょごにょ。

クラスを定義するとき使うpublic、alias_methodなどはModuleクラスのメソッドらしい。なので、定義機能を拡張できるとのこと。
よくわかってないのでとりあえず写経。

#!/usr/bin/env ruby

class Module
  @@docs = { }

  # クラスの定義時に呼ばれる
  def doc(str)
    @@docs[self.name] = self.name + ":?n" + str.gsub(/^?s+/, '')
  end

  def Module::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

module Another
  doc <<-edoc
And this is a documentation string
in a module
edoc
end

puts Module::doc(Example)
puts Module::doc("Another")

結果。

This is a sample documentation string
Another:
And this is a documentation string
in a module


プログラミングRuby 第2版 言語編

プログラミングRuby 第2版 言語編