From: Ken Bloom Date: 2006-10-16T22:35:16+09:00 Subject: Re: RDoc vs metaprogramming On Sun, 15 Oct 2006 13:31:18 +0900, ara.t.howard wrote: > 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. > > probably not what you wanted to here i know... Thanks for the tip. I certainly wanted to know, and last time I asked here, nobody knew the answer. --Ken -- Ken Bloom. PhD candidate. Linguistic Cognition Laboratory. Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/ I've added a signing subkey to my GPG key. Please update your keyring.