Learn
Introduction to Ruby
Single-Line Comments

You probably saw us use the # sign a few times in earlier exercises. The # sign is for comments in Ruby. A comment is a bit of text that Ruby won’t try to run as code: it’s just for humans to read. Writing good comments not only clarifies your code for other people who may read it, but helps remind you of what you were doing when you wrote the code days, months, or even years earlier.

The # sign should come before your comment and affects anything you write after it, so long as you’re on a single line. (We’ll show you how to do multi-line comments in a second.) Check out these examples:

# I'm a full line comment! "Eric".length # I'm a comment, too!

The second example will return 4, since the comment comes after the code that Ruby will execute.

Instructions

1.

Write a comment in the editor. It can be anything you like!

Folder Icon

Take this course for free

Already have an account?