Menu
Coddy logo textTech

Comments in Ruby

Part of the Fundamentals section of Coddy's Ruby journey — lesson 3 of 88.

Comments are notes you write inside your code. Ruby completely ignores them - they exist only to help humans understand the code.

To write a single-line comment, use the # symbol. Everything after # until the end of the line is ignored:

# This is a comment
puts "Hello!"

A comment can also be written at the end of a line, after the code:

puts "Hello!" # This prints Hello!

For comments that span several lines, use =begin to start and =end to end, each on its own line:

=begin
This is a multi-line comment.
Ruby ignores all of it.
=end
puts "Welcome!"

Comments can also temporarily disable a line of code without deleting it:

# puts "This line will NOT run"
puts "This line will run"

Note: Every multi-line comment that starts with =begin must be closed with =end, and both must be at the very start of their own lines.

challenge icon

Challenge

Beginner
Fix the code so that only Hello, Ruby! is printed.
  • Replace the ? character entirely with the # symbol to turn that line into a comment.
  • The line printing Goodbye! should become a comment so it does NOT run.
  • Ensure your final code looks like this: # puts "Goodbye!" followed by puts "Hello, Ruby!".

Try it yourself

# Type your code below
# TODO: Comment out the line below by adding a # at the start
puts "Goodbye!"
puts "Hello, Ruby!"
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals