Extended maintenance of Ruby 1.9.3 ended on February 23, 2015. Read more
Object
A section of documentation like:
# :section: The title # The body
Sections can be referenced multiple times and will be collapsed into a single section.
Creates a new section with title
and comment
# File rdoc/context.rb, line 128 def initialize parent, title, comment @parent = parent @title = title ? title.strip : title @@sequence.succ! @sequence = @@sequence.dup @comment = extract_comment comment end
Sections are equal when they have the same title
# File rdoc/context.rb, line 141 def == other self.class === other and @title == other.title end
Anchor reference for linking to this section
# File rdoc/context.rb, line 148 def aref title = @title || '[untitled]' CGI.escape(title).gsub('%', '-').sub(/^-/, '') end
Appends comment
to the current comment separated by a rule.
# File rdoc/context.rb, line 157 def comment= comment comment = extract_comment comment return if comment.empty? if @comment then @comment += "\n# ---\n#{comment}" else @comment = comment end end
Extracts the comment for this section from the original comment block. If the first line contains :section:, strip it and use the rest. Otherwise remove lines up to the line containing :section:, and look for those lines again at the end and remove them. This lets us write
# :section: The title # The body
# File rdoc/context.rb, line 178 def extract_comment comment if comment =~ /^#[ \t]*:section:.*\n/ then start = $` rest = $' if start.empty? then rest else rest.sub(/#{start.chomp}\Z/, '') end else comment end end
Section sequence number (deprecated)
# File rdoc/context.rb, line 200 def sequence warn "RDoc::Context::Section#sequence is deprecated, use #aref" @sequence end
Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.
If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.
If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.
If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.
Section comment