How to add RDoc documentation for a method defined using class_eval?
Asked Answered
Z

1

10

I am using class_eval to define a bunch of repetitive methods more concisely, something like this:

%w{greasy chunky bacon}.product(%w{flying sky poodle}).each do |a,b|
  class_eval "def #{a}_#{b}; do_something; end"
end

I would like all the resulting methods to be included in the RDoc documentation. Is there an RDoc directive which "manually" adds a method to the list of methods for the class? I can't find one.

Zandrazandt answered 13/8, 2012 at 2:27 Comment(0)
R
9

See the sections on Metaprogrammed Methods and Hidden methods and attributes in the RDoc documentation for RDoc::Parser::Ruby.

In your case, you would do something like:

##
# :method: greasy_flying
# Makes grease fly.

##
# :method: chunky_poodle
# This is a really gruesome method. Ewww!

And so on.

Rabies answered 13/8, 2012 at 12:47 Comment(1)
Awesome, I knew there must be something like this, but I was looking in the wrong place. Thanks! +1Zandrazandt

© 2022 - 2024 — McMap. All rights reserved.