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