2

Is there a way to have method names to be part of documentation for a class (for instance to look like this http://www.rubydoc.info/gems/activerecord/4.2.0/ActiveRecord/Explain) , if the methods were defined with define_method in a loop?

Code below for illustrative purposes - to be able to get the "methods" section in docs for this class to contain get_sunday, get_monday , etc..

WEEKDAYS.each do |day|

  #get all entities of a type e.g. get_nodes, get_pods, etc.
  define_method("get_#{day}) do ....
        #some logic here
  end

end

I saw that rdoc allows to specify :method, but it seems that it allows hardcoding the method name, while here I am looking whether a dynamic way exists to do it in a loop.

Neil Slater
  • 26,512
  • 6
  • 76
  • 94
nacrafts
  • 51
  • 1
  • Your example could do with some tidying (I've corrected formatting for you, but it would be better IMO if it was valid Ruby, even though it is just an illustrative example). Of course dynamic documentation is *not* going to actually describe your dynamic methods, at best it will capture the method signature, and maybe attach some generic text that applies to all the methods. So another improvement to the question would be to show how you expect your documentation for the example to look. The link to ActiveRecord docs doesn't help, nor seem relevant to dynamic docs. – Neil Slater Jan 05 '15 at 17:03
  • My expectation from the documentation would be as you wrote - just to simply list the names of the generated methods/method signature, nothing more. – nacrafts Jan 05 '15 at 17:35
  • See http://stackoverflow.com/questions/28413074/yard-doc-and-define-method – Christian Jan 26 '17 at 19:36

0 Answers0