Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Ruby Comments

Ruby Comments

Comments are lines within Ruby code that are ignored at runtime. A single-line comment starts with the # character and continues to the end of the line, as shown below:

Example

!/usr/bin/ruby -w

This is a single-line comment.

puts

"

Hello, Ruby!

"

Run Example »

When executed, the above program produces the following result:


Hello, Ruby!

Ruby Multi-line Comments

You can use the =begin and =end The syntax for commenting multiple lines is as follows:

Example

!/usr/bin/ruby -w

puts

"

Hello, Ruby!

"

=begin

This is a multi-line comment. It can extend to any number of lines. However, =begin and =end can only appear on the first and last lines.

=end

When executed, the above program produces the following result:


Hello, Ruby!

Make sure trailing comments are far enough from the code so they're easy to distinguish. If there is more than one trailing comment, align them. For example:

Example

@counter

Track the number of times a page is clicked

@siteCounter

Track all pages clicked