Ruby Comments

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

Ruby Comments

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:

#This is single line comment. 

Example:

  1. i = 10  #Here i is a variable.   
  2. 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 =endat the end of the line.

Syntax:

  1. =begin  
  2.     This  
  3.     is  
  4.     multi line  
  5.     comment  
  6. =end

  Example:

Output:

Ruby Comments 2