Ruby Comments
Comments in Ruby are lines within the code that are ignored during runtime. Single-line comments start with the #
character and continue until the end of the line, as shown below:
Example
#!/usr/bin/ruby -w
# This is a single-line comment.
puts "Hello, Ruby!"
When executed, the above program produces the following result:
Hello, Ruby!
Ruby Multiline Comments
You can comment multiple lines using the =begin
and =end
syntax, as shown below:
Example
#!/usr/bin/ruby -w
puts "Hello, Ruby!"
=begin
This is a multiline comment.
It can extend to any number of lines.
But `=begin` and `=end` should only appear on the first and last lines.
=end
When executed, the above program produces the following result:
Hello, Ruby!
Ensure that trailing comments are spaced far enough from the code to distinguish them easily. If there are more than one trailing comment, align them. For example:
Example
@counter # Tracks the number of times the page is clicked
@siteCounter # Tracks the number of times all pages are clicked