Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags


How to add comments in Ruby

okwudili onyejiaku

Comments are lines of annotation or code within a program that are ignored at run time. Comments aid in guiding, providing context, and conveying the meaning of code.

Types of comments

Comments on a particular line are called single-line comments.

When a comment spans more than one line, it is a multi-line comment.

Single-line comments

A single-line comment starts with the # character and extends from the # to the end of the line, as shown below.

# This is a single line comment.
puts "This is a single line comment in Ruby"

Multi-line comments

You can comment multiple lines with =begin and =end, as shown below.

puts "This is a multiline comment in Ruby"

This is a multiline comment and can span as many lines as you
like. But =begin and =end should come in the first and last line only. 



View all Courses

Keep Exploring