From: Robert Klemme Date: 2004-11-24T18:23:01+09:00 Subject: Re: adding class-methods via modules "John Wilger" schrieb im Newsbeitrag news:a05e51b6041123084753f0aa8@mail.gmail.com... > Hello, > > I have a module which, when a class includes the module, I would like > to have it add certain class-methods to the including class. > Currently, I am doing the following: > > module Foo > def self.included(mod) > mod.class_eval <<-EOF, __FILE__, __LINE__+1 > def self.bar > ... > end > EOF > end > end > > class Baz > include Foo > end > > This does accomplish the end goal---Baz::bar is a valid class > method---but it has the downside that RDoc doesn't pick up the class > methods defined inside Foo::included for documentation purposes. > > Is there either a) a way to get RDoc to pick up documentation for the > ::bar method (and simply document it as Foo::bar), or b) a better way > of creating these class methods on classes that include Foo that will > also allow RDoc to document these methods? Two options for b) come to mind: # option 1 module Foo module FooClassMethods def bar() puts "#bar#" end end def self.included(mod) class <