Comments

From RubySpec

Jump to: navigation, search

Comments are specified using the pound or hash character (#). Commented text extends from the hash character to the end of the line, and a comment can follow a line of uncommented code.

# This is a comment
# on two lines
x = 1 # This is a comment on the same line as uncommented code

There is also a form of multiline comment which starts with a line starting with the token =begin and ends at a line starting with the token =end.

 =begin
 This is a comment which
 spans multiple lines.
 =end

Each of the =begin and =end tokens must have the = character in the first column; no leading whitespace is allowed. One may put text after =begin to provide information to programs processing the comments:

 =begin rdoc
 This is an Rdoc comment.
 =end

Any such text must be separated from the =begin token by whitespace.

Ruby also supports a special documentation syntax called RubyDoc or RDoc which adds context-sensitive tags to comment lines. A post-processing tool can then run through Ruby source and pull out documentation based on these tags. RubyDoc is not part of the core language specification, but is the built-in and de-facto standard for creating inline documentation.

On Unix-like systems, the first line often contains a special comment similar to

 #! /usr/bin/env ruby

which tells the system how to execute the Ruby interpreter.

Personal tools