Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
We'll talk more about methods shortly, but I want to take a moment to tell you about another important feature of Ruby. Most programming languages support comments, snippets of text that you can insert into your code that are meant for humans to read, not the computer. Ruby supports comments, too.
- If you insert a pound sign (
#
), or hash mark, into your code, and it's not part of a string, Ruby will ignore all the text from the pound sign to the end of the line. - You can do this on a line by itself, or you can do it at the end of a line of code.
# Comment
puts "hello world" # Comment
-
0:00
We'll talk more about methods shortly, but
-
0:02
I want to take a moment to tell you about another important feature of Ruby.
-
0:06
Most programming languages support comments, snippets of text that you can
-
0:10
insert into your code that are meant for humans to read, not the computer.
-
0:14
Ruby supports comments, too.
-
0:16
Let's suppose you have some code and
-
0:18
you think it won't be immediately obvious to other developers what it does.
-
0:21
You can't just start typing an explanation.
-
0:25
Ruby will think the text is part of your program and
-
0:27
try to run it, which won't work.
-
0:30
Instead, you need to mark the text as something that shouldn't be run.
-
0:34
If you insert a pound sign, or hash mark, into your code and
-
0:37
it's not part of a string,
-
0:39
Ruby will ignore all the text from the pound sign to the end of the line.
-
0:43
You can do this on a line by itself, or
-
0:45
you can do it at the end of a line of code.
-
0:49
You can use this to leave useful comments throughout your code.
-
0:53
Any time where you write some code where the meaning isn't immediately obvious.
-
0:57
First you should try to rewrite the code so that it's clear all by itself.
-
1:00
But if that isn't possible for
-
1:02
whatever reason, you can add a comment that explains the code.
-
1:05
So let's add a quick explanation to this line of code here.
-
1:08
Prints hello world To the terminal.
-
1:18
Let's save that, and try running it.
-
1:22
And the first line is ignored because Ruby ignores everything from the pound sign
-
1:26
to the end of the line.
-
1:28
Only the second line actually gets run.
-
1:30
And now whenever you or any other developer looks at this code,
-
1:33
it will be immediately obvious what it does.
You need to sign up for Treehouse in order to download course files.
Sign up