【发布时间】:2012-09-28 16:57:56
【问题描述】:
block cmets 的具体规格是什么?第一行和最后一行必须完全以=begin 和=end 开头,这似乎是真的。但除此之外,还有一点不明确。一些描述说=begin 和=end 必须是各自行中唯一的东西,但这似乎不是真的。运行 Ruby 1.9.3 MRI,我得到以下结果。
添加空白字符似乎仍然有效:
=begin \t\t \t
This is not a Ruby command and should raise an exception if read.
=end \t\t\t \t\t\t\t
# => no problem
另外,好像我可以在一个或多个空格字符后面加一个任意字符串(不包括“\n”),还是可以的:
=begin \t\t \tblah blah blah
This is not a Ruby command and should raise an exception if read.
=end \t\t\t \t\t\t\tThis is some scribble
# => no problem
我可以在块注释中间放一行以=begin 开头的行:
=begin
This is not a Ruby command and should raise an exception if read.
=begin
So as this one.
=end
# => no problem
但不能作为评论的最后一行:
=begin
This is not a Ruby command and should raise an exception if read.
=end blah blah
So as this one.
=end
# => error
是这个规范,还是依赖于实现的行为?为了清楚起见,有人可以用正则表达式来描述 Ruby 块注释语法的确切规范吗?
【问题讨论】:
标签: ruby comments block-comments