- Ruby基础知识
 - Ruby - 主页
 - Ruby - 概述
 - Ruby - 环境设置
 - Ruby - 语法
 - Ruby - 类和对象
 - Ruby - 变量
 - Ruby - 运算符
 - Ruby - 评论
 - Ruby - IF...ELSE
 - Ruby - 循环
 - Ruby - 方法
 - Ruby - 块
 - Ruby - 模块
 - Ruby - 字符串
 - Ruby - 数组
 - Ruby - 哈希
 - Ruby - 日期和时间
 - Ruby - 范围
 - Ruby - 迭代器
 - Ruby - 文件 I/O
 - Ruby - 例外
 
Ruby - 评论
注释是 Ruby 代码中的注释行,在运行时会被忽略。单行注释以 # 字符开头,它们从 # 延伸到行尾,如下所示 -
#!/usr/bin/ruby -w # This is a single line comment. puts "Hello, Ruby!"
执行时,上述程序产生以下结果 -
Hello, Ruby!
Ruby 多行注释
您可以使用=begin和=end语法注释多行,如下所示 -
#!/usr/bin/ruby -w puts "Hello, Ruby!" =begin This is a multiline comment and con spwan as many lines as you like. But =begin and =end should come in the first line only. =end
执行时,上述程序产生以下结果 -
Hello, Ruby!
确保尾随注释距离代码足够远,并且易于区分。如果块中存在多个尾随注释,请将它们对齐。例如 -
@counter # keeps track times page has been hit @siteCounter # keeps track of times all pages have been hit