如何在Ruby中注释多行?


当前回答

=begin
My 
multiline
comment
here
=end

其他回答

=begin
My 
multiline
comment
here
=end
=begin
comment line 1
comment line 2
=end

确保=beginand=end是该行的第一项(没有空格)

使用以下任一项:

=begin
This
is
a
comment
block
=end

or

# This
# is
# a
# comment
# block

是rdoc目前唯一支持的两个,我认为这是一个很好的理由只使用这些。

#!/usr/bin/env ruby

=begin
Between =begin and =end, any number
of lines may be written. All of these
lines are ignored by the Ruby interpreter.
=end

puts "Hello world!"

尽管存在=begin和=end,但正常且更正确的注释方式是在每行上使用#。如果您阅读任何ruby库的源代码,您会发现几乎在所有情况下都是这样进行多行注释的。