解读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
相关推荐
  PMJ0    2020-10-13  
   longzhiwen    2020-09-06  
   yangxingstar    2020-08-31  
   LUCIEN0    2020-08-17  
   huangzihao00    2020-08-17  
   Jan    2020-08-17  
   AndesStay    2020-06-12  
   afengxg    2020-06-09  
   zamesking    2020-06-09  
   afengxg    2020-06-09  
   何志文    2020-06-09  
   teresalxm    2020-06-05  
   何志文    2020-05-16  
   何志文    2020-05-11  
   fsl    2020-05-04  
   JOO    2020-04-26  
   倩    2020-04-22  
   afanti    2020-04-19  
   始终不够    2020-04-10  
 