程序里的注释是很重要的。它们可以用自然语言告诉你某段程序代码的功能是什么。在你想要临时移除一段程序代码时,你还可以用注释的方式将这段程序代码临时禁用。接下来的练习将让你学会注释:
1 2 3 4 5 6 7 8 9 10 |
<span class="c"># A comment, this is so you can read your program later.</span> <span class="c"># Anything after the # is ignored by Ruby.</span> puts <span class="s2">"I could have code like this."</span> <span class="c"># and the comment after is ignored</span> <span class="c"># You can also use a comment to "disable" or comment out a piece of code:</span> <span class="c"># print "This won't run."</span> puts <span class="s2">"This will run."</span> |
