![]() |
VOOZH | about |
Statements that are not executed by the compiler and interpreter are called Comments. During coding proper use of comments makes maintenance easier and finding bugs easily.
In Ruby, there are two types of comments:
Here, we are going to explain both types of comment with their syntax and example:
It is represented by # sign. It is used to denote single line comment in Ruby. Its the most easiest typed comments. When we need only one line of a comment in Ruby then we can use the characters ‘#’ preceding the comment.
Example :
Output:
Single line comment above
If our comment is extending in more than one line than we can use a multiline comment.In Ruby, Multi- Line Comment started by using =begin and ended by using =end syntax.
Syntax :
=begin continues continues . . . Comment ends =end
Example :
Output:
Multi line comments below
We can also execute single line comments by using the above syntax as shown below:
=begin Comment line 1 =end