On Sun, 15 Oct 2006, Pau Garcia i Quiles wrote: > Hello, > > I have developed a library to read and parse XSPF playlists. Most of the > methods (90%) are metagenerated using something like this: > > class XSPFBlah > > attributes = %w{ attrib1 attrib2 } > attributes.each do |attrib| > define_method(attrib.to_sym) { do_something } > end > > def initialize(source) > do something > end > end > > RDoc does not find the metaprogrammed methods, therefore the documentation is > useless. Is there anything I could do to get RDoc to work? > > Thank you. this is one reason using module_eval(string) is better than using define_method et al. eg $META_RDOC = ENV['META_RDOC'] class XSPFBlah attributes = %w{ attrib1 attrib2 } attributes.each do |attrib| code <<-code def #{ attrib }() do_something end code module_eval code if $META_RDOC open($META_RDOC, 'a+') do |f| f.puts code end end end def initialize(source) do something end end obviously you need to tweak this a little, so the methds land in XSPFBlah, for instance. but it's immensely useful both for debugging and for documenting. if you go this route it's generally useful to pull __all__ of you meta-programming methods into their own module. for instance: module MetaGen def self.add_some_meta_method klass, attrib code <<-code def #{ attrib }() do_something end code klass.module_eval code # hook to write klass + name attrib to a file end end class XSPFBlah (attributes = %w{ attrib1 attrib2 }).each{|a| MetaGen.add_some_meta_method self, attrib} end probably not what you wanted to here i know... -a -- my religion is very simple. my religion is kindness. -- the dalai lama