Ruby Comments
Comments are lines of annotation within Ruby code that are ignored at runtime. A single-line comment starts with the # character and continues until the end of the line, as shown below:
When executed, the above program will produce the following result:
Hello, Ruby!
Ruby Multi-line Comments
You can use=beginand=endsyntax to comment multiple lines, as shown below:
Examples
#!/usr/bin/ruby -w
puts "Hello, Ruby!"
=beginThis is a multi-line comment.
It can be extended to any number of lines.
But =begin and =end can only appear on the first line and the last line.=end
When executed, the above program will produce the following result:
Hello, Ruby!
Please make sure trailing comments are spaced far enough from the code to make it easy to distinguish comments from code. If there is more than one trailing comment, align them. For example:
Examples
@counter #Track the number of times a page is clicked
@siteCounter #Track the number of times all pages are clicked