O'Reilly logo

Learn Ruby the Hard Way: A Simple and Idiomatic Introduction to the Imaginative World of Computational Thinking with Code, Third Edition by Zed A. Shaw

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Exercise 2. Comments and Pound Characters

Comments are very important in your programs. They are used to tell you what something does in English, and they are used to disable parts of your program if you need to remove them temporarily. Here’s how you use comments in Ruby:

ex2.rb

 1    # A comment, this is so you can read your program later.  2    # Anything after the # is ignored by ruby.  3  4    puts "I could have code like this." # and the comment after is ignored  5  6    # You can also use a comment to "disable" or comment out a piece of code:  7    # puts "This won't run."  8  9    puts "This will run."

From now on, I’m going to write code like this. It is important for you to understand that everything does ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required