如何在Ruby中注释多行?

推荐答案

#!/usr/bin/env ruby

=begin
Every body mentioned this way
to have multiline comments.

The =begin and =end must be at the beginning of the line or
it will be a syntax error.
=end

puts "Hello world!"

<<-DOC
Also, you could create a docstring.
which...
DOC

puts "Hello world!"

"..is kinda ugly and creates
a String instance, but I know one guy
with a Smalltalk background, who
does this."

puts "Hello world!"

##
# most
# people
# do
# this


__END__

But all forgot there is another option.
Only at the end of a file, of course.
  • 这就是它的样子(通过截图)——否则很难解释上面的 comments 会是什么样子.Click to Zoom-in:

Comments in a text-editor

Ruby相关问答推荐

如何保证散列中的对象不完全相同

如何在 Ruby 中正确编写代码?以便它产生正确的输出?

Rb:仅通过在 Ruby 中的类上添加 each 方法,可枚举模块是如何工作的?

Ruby 中的 Hash[key] 返回 nil 但 hash 没有 nil 值

判断一个数组是否是Ruby中另一个数组的子集

将 pp 的结果(或输出到控制台的任何内容)放入字符串

Symfony 2assets资源过滤器异常中的指南针

带有索引的 Ruby `each_with_object`

如何使用 RVM 重新编译 ruby​​?

判断字符串是否包含Ruby数组中的任何子字符串

如果尚未定义,则设置 Ruby 变量

动态设置 Ruby 对象的属性

使用哈希参数进行 DRY Ruby 初始化

在命名包含多个单词的Ruby 时,是否应该使用破折号或下划线?

了解 Ruby 的加载路径

错误数量的参数(1 代表 0)在 Ruby 中是什么意思?

在 Ruby 脚本中解析命令行参数

何时在 Ruby 中使用 `require`、`load` 或 `autoload`?

Ruby 中的 each 和 collect 方法有什么不同

为什么我们在 Ruby 中有 0.0 和 -0.0?