Extended maintenance of Ruby 1.9.3 ended on February 23, 2015. Read more

In Files

  • rdoc/context.rb
  • rdoc/generator/markup.rb

Class/Module Index [+]

Quicksearch

RDoc::Context::Section

A section of documentation like:

# :section: The title
# The body

Sections can be referenced multiple times and will be collapsed into a single section.

Attributes

comment[R]

Section comment

parent[R]

Context this Section lives in

title[R]

Section title

Public Class Methods

new(parent, title, comment) click to toggle source

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
            

Public Instance Methods

==(other) click to toggle source

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
            
aref() click to toggle source

Anchor reference for linking to this section

 
               # File rdoc/context.rb, line 148
def aref
  title = @title || '[untitled]'

  CGI.escape(title).gsub('%', '-').sub(/^-/, '')
end
            
comment=(comment) click to toggle source

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
            
extract_comment(comment) click to toggle source

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
            
sequence() click to toggle source

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.