|
Comments as the term states itself are the lines which are although written with the code at the time of programming but they are always ignored at the time of execution of that code.
The basic purpose of putting these lines in the code is to make the code properly understandable and easy to trace the functionality of that code in the future by the programmers other than the originator of that code segment. It is suggested to mention the copyright, author name, filename, version number and license terms in the comment section so as to maintain the proper history and records of the code.
For example:# Copyright © 2001, Richard Willy
In Ruby the comments are extended with the symbol “#” to the end of the line.
For example:
1. # this symbol states that it is a comment.
For Example:
# This is my first Ruby program
# I am excited to learn Ruby!!
puts 'My First Ruby Program'
2. We can have comments in this way also in Ruby code.
=begin
This is another way of putting document.
=end
For Example:
=begin
This is my first Ruby Program
print "My First Ruby Program".
=end
puts 'My First Ruby Program'
An Example showing the implemenatation of above mentioned Comment syntax:
# This basic program Demonstrates how to
# use comments in Ruby programming
puts "john"+"David"+"Mary"
# The above code will print all names without space in between
puts "John "+"David "+"Mary "
# This will print all three names with one space in between each name.
Comment on footer of program giving details of the author of the code:
=begin
* Name:
* Description
* Author:
* Date:
* License:
=end
Program demonstrating implementation of comments
if b == 2
true # special case
else
prime?(b) # work only if b is odd
end
|