Comments in Ruby
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:
- Single – line comments.
- Multi – line comments.
Here, we are going to explain both types of comment with their syntax and example:
Ruby Single-Line Comments –
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.
Single line comment above
Ruby Multi-Line Comments –
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.
=begin continues continues . . . Comment ends =end
Multi line comments below
We can also execute single line comments by using the above syntax as shown below:
=begin Comment line 1 =end
Please Login to comment...