Using tomdoc to document a scope in a Rails model

Thoughts from the team
By    | November 28, 2012 | Code Snippets,

I’m playing around with Tomdoc for documenting my latest Rails project.  The documentation is (ironically) a bit thin on the ground.  It’s taking a bit of trial and error to get some things working.  The most recent brainteaser was how to get tomdoc (or even rdoc) to document a scope declared on a Rails model.

The answer is that you need to have a line with two ## at the start for the parser to pick it up.  For example:

  ##
  # Public: Scope to return the most recently logged entries, ordered
  # by the date the were created, newest first
  #
  # count - The number of entries to return.  Default 6.
  scope :recently_logged, ->(count=6) { order('created_at DESC').limit(count) }

 

That gives you a section like this in your docs:

More like this