- Ruby 基礎
- Ruby - 主頁
- Ruby - 概覽
- Ruby - 環境設定
- Ruby - 語法
- Ruby - 類和物件
- Ruby - 變數
- Ruby - 運算子
- Ruby - 註釋
- Ruby - IF...ELSE
- Ruby - 迴圈
- Ruby - 方法
- Ruby - 塊
- Ruby - 模組
- Ruby - 字串
- Ruby - 陣列
- Ruby - 雜湊
- Ruby - 日期和時間
- Ruby - 範圍
- Ruby - 迭代器
- Ruby - 檔案 I/O
- Ruby - 異常
Ruby - 註釋
註釋是在 Ruby 程式碼中通常被忽略的執行時註解行。單行註釋以 # 字元開頭,從 # 開始並一直延續到行尾,如下所示 −
#!/usr/bin/ruby -w # This is a single line comment. puts "Hello, Ruby!"
執行上述程式時,將產生以下結果 −
Hello, Ruby!
Ruby 多行註釋
可以使用 =begin 和 =end 語法對多行進行註釋,如下所示 −
#!/usr/bin/ruby -w puts "Hello, Ruby!" =begin This is a multiline comment and con spwan as many lines as you like. But =begin and =end should come in the first line only. =end
執行上述程式時,將產生以下結果 −
Hello, Ruby!
確保尾隨註釋與程式碼有足夠的距離,並且很容易辨別。如果在一個塊中存在多個尾隨註釋,請將它們對齊。例如,−
@counter # keeps track times page has been hit @siteCounter # keeps track of times all pages have been hit
廣告