ruby supports comments. A comment is text that is ignored on execution.
but may be useful to the programmer. You can add any kind of text inside
your code.

Ruby ignores comments. Comments can be single line or multi line.

Download Free Ruby Ebook

Quick Start

Comments in ruby

Write some code. In this example we output some text.
Then add single and multi line comments.

Copy the code below and save the file as hello.rb

1
2
3
4
5
6
7
8
9
10
11
#!/usr/bin/ruby -w

# This is a single line comment.
puts "Ruby code!"

=begin
This is a multi line comment
Yes, you can type multiple
lines of comment.
=end
puts "Ruby code!"

Execute with:

1
ruby example5.rb

Exercises

  1. Create a program and add a comment with your name
  2. When would you use multiline comments over single line?
  3. Can you write code and comments on the same line?