Ruby 注释

Ruby 教程 · 2019-02-18 23:29:05

注释是在运行时会被忽略的 Ruby 代码内的注释行。单行注释以 # 字符开始,直到该行结束,如下所示:

实例

#!/usr/bin/ruby -w # 这是一个单行注释。 puts "Hello, Ruby!"

当执行时,上面的程序会产生以下结果:

Hello, Ruby!

Ruby 多行注释

您可以使用 =begin 和 =end 语法注释多行,如下所示:

实例

#!/usr/bin/ruby -w puts "Hello, Ruby!" =begin 这是一个多行注释。 可扩展至任意数量的行。 但 =begin 和 =end 只能出现在第一行和最后一行。 =end

当执行时,上面的程序会产生以下结果:

Hello, Ruby!

请确保尾部的注释离代码有足够的距离,以便容易区分注释和代码。如果尾部超过一条注释,请将它们对齐。例如:

实例

@counter # 跟踪页面被点击的次数 @siteCounter # 跟踪所有页面被点击的次数

点击查看所有 Ruby 教程 文章: https://www.codercto.com/courses/l/16.html

查看所有标签

Artificial Intelligence

Artificial Intelligence

Stuart Russell、Peter Norvig / Pearson / 2009-12-11 / USD 195.00

The long-anticipated revision of this #1 selling book offers the most comprehensive, state of the art introduction to the theory and practice of artificial intelligence for modern applications. Intell......一起来看看 《Artificial Intelligence》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

在线进制转换器
在线进制转换器

各进制数互转换器

html转js在线工具
html转js在线工具

html转js在线工具