Ad space (banner)
๐Ÿ’ŽRuby Lessons
Lesson 17 / 68

Writing Comments

In this lesson you will learn how to write comments in Ruby so your code still makes sense when you come back to it. This is for anyone searching for "Ruby comment out syntax".

A comment is a note for humans that has no effect on execution. # starts a single-line comment, and =begin to =end handles several lines.

The sample code uses both a # single-line comment and a multi-line comment from =begin to =end. Notice that none of it affects the output - it exists purely as explanation for a human reader.

A common stumbling block for beginners is writing so many comments that the code becomes harder to read. What the code does is usually clear from the code itself, so comments are most effective when they capture why a piece of logic is needed.

Comments are also the usual way to disable code temporarily, which makes them indispensable in practice. Turning off a single line to check behaviour while debugging is a very common move.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run Ruby directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)