Ruby - 注释符

Ruby - 注释符 首页 / Ruby入门教程 / Ruby - 注释符

注释是Ruby代码中的注释行,在运行时会被忽略。一行注释以#字符开头,它们从#延伸到该行的末尾,如下所示-

#!/usr/bin/ruby -w
# This is a single line comment.

puts "Hello, Ruby!"

执行后,上述程序会产生以下输出-

链接:https://www.learnfk.comhttps://www.learnfk.com/ruby/ruby-comments.html

来源:LearnFk无涯教程网

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

执行后,上述程序会产生以下输出-

链接:https://www.learnfk.comhttps://www.learnfk.com/ruby/ruby-comments.html

来源:LearnFk无涯教程网

Hello, Ruby!

确保尾随注释与代码之间的距离足够远,并且易于区分。如-

@counter      # keeps track times page has been hit
@siteCounter  # keeps track of times all pages have been hit

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

朱赟的技术管理课 -〔朱赟〕

用户体验设计实战课 -〔相辉〕

容量保障核心技术与实战 -〔吴骏龙〕

如何读懂一首诗 -〔王天博〕

云原生架构与GitOps实战 -〔王炜〕

结构思考力 · 透过结构看思考 -〔李忠秋〕

LangChain 实战课 -〔黄佳〕

AI大模型企业应用实战 -〔蔡超〕

互联网人的数字化企业生存指南 -〔沈欣〕

好记忆不如烂笔头。留下您的足迹吧 :)