1
塊註釋的確切規格是什麼?似乎確實,第一行和最後一行必須以和=end
開頭。但除此之外,還有一點不明朗之處。一些描述說,和=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
Furturemore,看來我可以添加任意字符串(不包括「\ 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
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塊註釋語法的確切規範嗎?
其實,這仍不能準確地一樣我得到的結果。評論似乎能夠在沒有空間的情況下遵循標籤序列。 – sawa