程序里面的注释是非常重要的。它们可以用自然语言告诉你某段代码的功能是什么,同时,在你想临时删除某段代码时,也可以用注释的方式来将这段代码临时禁用。下面的练习将会让你学会Ruby里面的注释:
-
# A comment, this is so you can read your program later.
-
# Anything after the # is ignored by Ruby.
-
puts "I could have code like this." # and the comment after is ignored
-
# You can also use a comment to "disable" or comment out a piece of code:
-
# print "This won't run."
-
puts "This will run."
你应该看到的结果
$ ruby ex2.rb
I could have code like this.
This will run.
$
加分习题
-
1. 弄清楚 # 符号的作用,并且记住它的名称。(中文为井号,英文为 octothorpe 或者 pound character)。
-
2. 打开你的 ex2.rb 文档,从后往前逐行检查。从最后一行开始,倒着逐个单词检查回去。
-
3. 有发现更多错误吗?有的话就改正过来。
-
4. 阅读你写的习题,把每个字符(charcter)都读出來。有没有发现更多的错误呢?有的话也一样改正过来。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/11379785/viewspace-1215399/
,如需转载,请注明出处,否则将追究法律责任。