I am currently learning Ruby through Zed Shaw’s Learn Ruby the Hard Way. I will document my progress and takeaway thoughts as I go through each exercise.
My Work for Exercise 1:
1. Make your script print another line.
Using the puts method on the string “Here is another line.”, I added another line to the output.
2. Make your script print only one of the lines.
By putting an octothorpe (pound) symbol in front of the lines of code, we turn them into comments that Ruby ignores. Only the string in line 7 will be printed. I decided to leave line 7 since it says “do not touch this”, but you can leave any one of the lines to be printed by omitting the # in front.
3. Put a # (octothorpe) character at the beginning of a line. What did it do? Try to find out what this character does.
The octothorpe character indicates to Ruby that the line is a comment and skips it. If you want to create a multi-line comment, you put # in front of every line that is a comment. Here is an example.
Another way is to use =begin and =end with the comments in between. =begin and =end must be at the beginning of a line. Using # is more readable.