← Back to Ruby Course | Chapter 1: Setup & Basics | Lesson 6 of 7

Comments

In this page:

  1. Comments

Comments

A # starts a single-line comment in Ruby, and everything after it on that line is ignored. Multi-line comments use =begin and =end, though single-line # comments are far more common in practice. Comments should explain non-obvious reasoning, not restate what the code already makes clear.

Note: Most Ruby style guides discourage =begin/=end blocks in favor of multiple # lines.

Example: Comments

markup
# This script demonstrates comments
puts "Hello!"  # inline comment after code

=begin
This is a multi-line comment block,
though single-line # comments are more idiomatic.
=end

puts "Still running"
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.