注释是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
参考链接
https://www.learnfk.com/ruby/ruby-comments.html
标签:begin,教程,end,Ruby,无涯,注释,ruby,Hello From: https://blog.51cto.com/u_14033984/8475256