From: Dave Thomas Date: 2002-01-27T00:05:47+09:00 Subject: Re: RDoc: eval("class A; ... end") GOTO Kentaro writes: > In message "Re: RDoc: eval("class A; ... end")" > Oh, that is not simple. Maybe dynamically defined class is the source > of complexty. Right now I'm looking at executing selected pieces of source code, and then using them to generate additional source that I feed to RDoc. So, in your example, I might have: #:rdoc-eval:start StatusMessage = { 100, 'Continue', 101, 'Switching Protocols', .... 504, 'Gateway Timeout', 505, 'HTTP Version Not Supported' } CodeToError = {} StatusMessage.each{|code, message| var_name = message.gsub(/[ -]/,'_').upcase err_name = message.gsub(/[ -]/,'') case code when 100...200; parent = Info when 200...300; parent = Success when 300...400; parent = Redirect when 400...500; parent = ClientError when 500...600; parent = ServerError end eval %- RC_#{var_name} = #{code} #> # Error message: #{StatusMessage[code] #> class #{err_name} < #{parent} #> ends class #{err_name} < #{parent} def code; RC_#{var_name}; end alias to_i code def reason_phrase; StatusMessage[code]; end end - CodeToError[code] = const_get(err_name) } #rdoc-eval:end The lines with '#>' are like a kind of 'puts' - they inject the rest of the line back in to the source. In this example, the first line is the comment used to document the class, and the next two define it. Would something like this work for people? Dave