Ruby Comments

by

in

Ruby comments are non executable lines in a program. These lines are ignored by the interpreter hence they don’t execute while execution of a program. They are written by a programmer to explain their code so that others who look at the code will understand it in a better way.

Types of Ruby comments:

  • Single line comment
  • multi line comment

Ruby Single Line Comment

The Ruby single line comment is used to comment only one line at a time. They are defined with # character.

Syntax:

  1. #This is single line comment.  

Example:

i = 10  #Here i is a variable.   

puts i

Output:

Ruby Comments 1

The Ruby multi line comment is used to comment multiple lines at a time. They are defined with =begin at the starting and =end at the end of the line.

Syntax:

=begin  

    This  

    is  

    multi line  

    comment  

=end

Example:

=begin   

we are declaring   

a variable i   

in this program   

=end   

i = 10   

puts i

Output:

Ruby Comments 2

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *