1、ofanimal4. +dog+alsopet5. =levalone6. =two7. andsoon8. -9. howaboutthis10. 11. deffoo(name)12. namename13. end14. 15. 16. Extracttheagecalculate17. date-of-birth.18. #-19. FIXME:failsifbirthdayfalls20. February29th21. #+22. TheDOBisreturnedasTimeobject.23. 24. get_dob(person)25. 26. 27. end效果class D
2、emoPublic Instance Methodsfoo(name) 测试cata kind of animaldogalso a petleval one leval twoand so onhow about this get_dob(person)Extract the age and calculate the date-of-birth. The DOB is returned as aTime object.通常使用rdoc命令来为ruby程序生成文档eg:rdoc test.rb如果要对整个项目的rb文件生成文档只需在rdoc命令后不带文件名rdoc如果有类和方法不想生成doc
3、def no_doc #:nodoc:end或class NoDocClass #:all部分注释不想生成doc#-#该行不会生成doc#+#该行会生成docrdoc命令:-all:rdoc默认只将共有方法生成doc,使用-all会将所有方法生成doc-fmt 用指定格式生成文档-help:-inline-source:将代码显示在文档中-main设置主索引页面的名字-one-file:将rdoc所有文档内容放在一个文件中-op设置输出目录的目录名RDOC - Ruby Documentation SystemThis package contains Rdoc and SimpleMarku
4、p. Rdoc is an application that produces documentation for one or more Ruby source files. We work similarly to JavaDoc, parsing the source, and extracting the definition for classes, modules, and methods (along with includes and requires). We associate with these optional documentation contained in t
5、he immediately preceding comment block, and then render the result using a pluggable output formatter. (Currently, HTML is the only supported format. Markup is a library that converts plain text into various output formats. The Markup library is used to interpret the comment blocks that Rdoc uses to
6、 document methods, classes, and so on.InstallationThis distribution contains two packages, rdoc itself and a text markup library, markup. You can install them both using the single command % ruby install.rbin this directory. If you just want to install , change to the markup directory and run the in
7、stall.rb script there.Roadmap If you want to use Rdoc to create documentation for your Ruby source files, read on. If you want to include extensions written in C, seerdoc/parsers/parse_c.rb. For information on the various markups available in comment blocks, seemarkup/simple_markup.rb. If you want t
8、o drive Rdoc programatically, seeRDoc:RDoc. If you want to use the library to format text blocks into HTML, have a look atSM:SimpleMarkup. If you want to try writing your own HTML output template, seePage.SummaryOnce installed, you can create documentation using the rdoc command (the command is rdoc
9、.rb under Windows) % rdoc options names.Type rdoc -help for an up-to-date option summary.A typical use might be to generate documentation for a package of Ruby source (such as rdoc itself). % rdocThis command generates documentation for all the Ruby and C source files in and below the current direct
10、ory. These will be stored in a documentation tree starting in the subdirectory doc.You can make this slightly more useful for your readers by having the index page contain the documentation for the primary file. In our case, we could type % rdoc -main rdoc/rdoc.rbYoull find information on the variou
11、s formatting tricks you can use in comment blocks in the documentation this generates.RDocuses file extensions to determine how to process each file. File names ending.rb.rbware assumed to be Ruby source. Files ending.care parsed as C files. All other files are assumed to contain just SimpleMarkup-s
12、tyle markup (with or without leading # comment markers). If directory names are passed toRDoc, they are scanned recursively for C and Ruby source files only.Credits The Ruby parser in rdoc/parse.rb is based heavily on the outstanding work of Keiju ISHITSUKA of Nippon Rational Inc, who produced the R
13、uby parser for irb and the rtags package. Code to diagram classes and modules was written by Sergey A Yanovitsky (Jah) of Enticla. Charset patch from MoonWolf. Rich Kilmer wrote the kilmer.rb output template. Dan Brickley led the design of the RDF format.Licenseis Copyright (c) 2001-2003 Dave Thomas
14、, The Pragmatic Programmers. It is free software, and may be redistributed under the terms specified in theREADMEfile of the Ruby distribution.SupportThe Rdoc homepage is. There youll find links for downloading the Rdoc package, and instructions on how to get the still-quivering sources from CVS. Im
15、 also using Sourceforge to track bugs and manage feature requests. If you submit patches, it would help if they were inline (not attachments) and generated using diff -u. I dont have access to a wide variety of browsers, so reports that output looks funny under Browser XYZ arent too helpful: far bet
16、ter are suggested changes to the generated HTML that fix the problem.For other information, feel free to ask on the ruby-talk mailing list (which is mirrored to comp.lang.ruby) or contactdave.Usageis invoked from the command line using: % rdoc name.Files are parsed, and the information they contain
17、collected, before any output is produced. This allows cross references between all files to be resolved. If a name is a directory, it is traversed. If no names are specified, all Ruby files in the current directory (and subdirectories) are processed.Options are:-allinclude protected and private meth
18、ods in the output (by default only public methods are included)-mainnameset the class, module, or file to appear on the index page-excludepatternexclude files and directories matching this pattern from processing-quietdo not display progress messages-one-fileplace all the output into a single file-o
19、pdirset the output directory todir(the default is the directory doc)-opnameset the output name (has no effect for HTML).-charsetcharsetSet the character set for the generated HTML.-fmtfmtgenerate output in a particular format.-includedir,.specify one or more directories to be searched when satifying
20、 given. The directory containing the file currently being processed is always searched.-inline-sourceBy default, the source code of methods is shown in a popup. With this option, its displayed inline.-show-hashA name of the form name in a comment is a possible hyperlink to an instance method name. W
21、hen displayed, the is removed unless this option is specified-templatespecify an alternate template to use when generating output (the default is standard). This template should be in a directory accessible via $: as rdoc/generators/xxxx_template, where xxxx depends on the output formatter.-diagrami
22、nclude diagrams showing modules and classes. This is currently an experimental feature, and may not be supported by all output templates. You need dot V1.8.6 or later to use the -diagram option correctly (ExampleA typical small Ruby program commented usingmight be as follows. You can see the formatt
23、ed result in EXAMPLE.rb andAnagram. # The program takes an initial word or phrase from # the command line (or in the absence of a # parameter from the first line of standard # input). In then reads successive words or # phrases from standard input and reports whether # they are angrams of the first
24、word. # # Author: Dave Thomas (mailto:davex.y) # Copyright: Copyright (c) 2002 The Pragmatic Programmers, LLC # License: Distributes under the same terms as Ruby # This class holds the letters in the original # word or phrase. The is_anagram? method allows us # to test if subsequent words or phrases
25、 are # anagrams of the original. class Anagram # Remember the letters in the initial word def initialize(text) initial_letters = letters_of(text) end # Test to see if a new word contains the same # letters as the original def is_anagram?(text) initial_letters = letters_of(text) # Determine the lette
26、rs in a word or phrase # * all letters are converted to lower case # * anything not a letter is stripped out # * the letters are converted into an array # * the array is sorted # * the letters are joined back into a string def letters_of(text) text.downcase.delete(a-z).split().sort.join tester = Ana
27、gram.new(ARGV.shift | gets) ARGF.each do |text| puts Anagram! if tester.is_anagram? textMarkupComment blocks can be written fairly naturally.Paragraphs are lines that share the left margin. Text indented past this margin are formatted verbatim.1. Lists are typed as indented paragraphs with:o a * or
28、- (for bullet lists)o a digit followed by a period for numbered listsFor example, the input that produced the above paragraph looked like 1. Lists are typed as indented paragraphs with: * a * a digit followed by a period for numbered lists2. Labeled lists (sometimes called description lists) are typ
29、ed using square brackets for the label.3. cat small domestic animal4. +cat+ command to copy standard input5. Labeled lists may also be produced by putting a double colon after the label. This sets the result in tabular form, so the descriptions all line up. This was used to create the author block at the bottom of