As you start to write more complicated programs, it will become necessary to start using comments. Comments allows you to add explanations to your code, so that other developers (and you) can always understand what a particular piece of code is for. It's good practice to comment your code extensively.

There are two types of comments, multi-line comments, and single-line comments. Single-line are started with # and multi-line comments are started with =begin and ended with =end.

I'm a comment!

Single-line comments can be started after another thing in the same line.

puts "Hi!" #I'm a comment, but Hi! will still be printed to the console.


Using whichever method you prefer, comment everything out EXCEPT "Don't comment me out!" still needs to be printed out.

Copyright © Read our Terms of Use and Privacy Policy