Ruby 中的多行註釋

Stewart Nguyen 2022年5月18日
Ruby 中的多行註釋

與所有其他程式語言一樣,Ruby 也支援開箱即用的註釋語法。

我們可以使用數字符號字元 # 在 Ruby 程式碼中進行單行註釋。

Ruby 中的多行註釋

在 Ruby 中,多行註釋語法以 =begin 標記開始,以 =end 標記結束。它被稱為塊註釋。

這些標記中不應有前導空格。

=begin
Quisque velit nisi, pretium ut lacinia in, elementum id enim.
Praesent sapien massa, convallis a pellentesque nec, egestas non nisi.
Donec rutrum congue leo eget malesuada.
Curabitur arcu erat, accumsan id imperdiet et, porttitor at sem.
=end

儘管 Ruby 有 =begin/=end 語法來進行多行註釋,但大多數 Ruby 開發人員更喜歡單行語法,它可以跨越多行並且推薦

# This is also
#   multi-line comments