您现在的位置: 万盛学电脑网 >> 程序编程 >> 网络编程 >> 编程语言综合 >> 正文

Ruby中注释的使用方法

作者:佚名    责任编辑:admin    更新时间:2022-06-22

   这篇文章主要介绍了解读Ruby中注释的使用方法,注释的用法是每门编程语言中最基本的知识点之一,需要的朋友可以参考下

  Ruby行内注释的代码在运行时被忽略。单行注释#字符开始,他们从#到行末如下:

  ?

1 2 3 4 5 #!/usr/bin/ruby -w   # This is a single line comment.   puts "Hello, Ruby!"

  上述程序执行时,会产生以下结果:

  ?

1 Hello, Ruby!

  Ruby的多行注释

  可以注释掉多行使用 =begin 和 =end 语法如下:

  ?

1 2 3 4 5 6 7 8 #!/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

  上述程序执行时,会产生以下结果:

  ?

1 Hello, Ruby!

  确保后面的注释是保持足够的距离的代码,能使它很容易区分。如果在一个块中存在一个以上的尾端注释它们对齐。例如:

  ?

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