Changes

Commenting Ruby Code

34 bytes added, 13:51, 31 March 2009
no edit summary
Commenting code is a little like going to the dentist. We don't really want to have to do it but deep down we know it is a good thing to do. No matter how well written and self-explanatory your Ruby script it is still good practice to add comments. There a number of reasons for doing this. Firstly, it is possible that someone else may one day have to modify or fix bugs in your code. Good comments will help those who are new to your code to understand what it does. Secondly, now no matter how well you understand your Ruby scripts now, I can assure you that in 6 months time you will look at the code and wonder how it all fits together (trust me, I've been programming for a long time and sometimes return to something I developed years ago and cannot believe I even wrote it!).
Comments are also useful for blocking out lines of code that you no longer wish to run (typically something that is done when trying to debug problems in complex programs).
== What is Exactly exactly is Commenting ==
Commenting is the process of marking content in a program such that it is ignored by the Ruby interpreter. This is typically used so that the programmer can write notes alongside the code describing what that code does such that other humans who look at the code will have a better chance of understanding the code.
</pre>
Although a better way to implement multi-line comments is to use the comment begin and end markersas described later in this chapter.
== Comments on Lines of Code ==
</pre>
Note that ''everything'' on the line after the '#' is ignored by the Ruby interpreter. You cannot, therefore, put more code after the '#' and expect it to be executed. Additional code must be placed on the next line.
== Multi Line or Block Ruby Comments ==