Kon*_*ase 1322
#!/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.
Run Code Online (Sandbox Code Playgroud)
Ada*_*ear 124
=begin
My
multiline
comment
here
=end
Run Code Online (Sandbox Code Playgroud)
Rei*_*chs 54
尽管存在=begin和=end,正常和更正确的评论方式是#在每一行使用's.如果您阅读任何ruby库的源代码,您会发现这几乎是所有情况下多线注释的完成方式.
mik*_*iku 19
#!/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!"
Run Code Online (Sandbox Code Playgroud)
the*_*Man 16
使用:
=begin This is a comment block =end
要么
# This # is # a # comment # block
是rdoc目前唯一支持的两个,这是我认为只使用这些的一个很好的理由.
La-*_*eja 13
=begin
(some code here)
=end
Run Code Online (Sandbox Code Playgroud)
和
# This code
# on multiple lines
# is commented out
Run Code Online (Sandbox Code Playgroud)
都是正确的.第一种评论的优点是可编辑性 - 它更容易取消注释,因为删除的字符越少.第二种注释的优点是可读性 - 逐行读取代码,更容易判断特定行已被注释掉.你的电话,但想想谁跟你在一起,以及他们阅读和维护是多么容易.
Pra*_*thi 12
这是一个例子:
=begin
print "Give me a number:"
number = gets.chomp.to_f
total = number * 10
puts "The total value is : #{total}"
=end
Run Code Online (Sandbox Code Playgroud)
所有你放在间=begin和=end会的代码有多少行包含之间无论视为注释.
注意:确保=和之间没有空格begin:
=begin= begin=begin
comment line 1
comment line 2
=end
Run Code Online (Sandbox Code Playgroud)
确保=begin并且=end是该行的第一件事(没有空格)