手机
当前位置:查字典教程网 >脚本专栏 >ruby专题 >解读Ruby中注释的使用方法
解读Ruby中注释的使用方法
摘要:Ruby行内注释的代码在运行时被忽略。单行注释#字符开始,他们从#到行末如下:#!/usr/bin/ruby-w#Thisisasingle...

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

【解读Ruby中注释的使用方法】相关文章:

Ruby中检测Gem是否安装的方法

Ruby中遍历目录的简洁方法

浅析Ruby中的Profiling工具的用法

Ruby中的方法(函数)学习总结

初步讲解Ruby编程中的多线程

Ruby中的Mechanize的使用教程

在Ruby on Rails中优化ActiveRecord的方法

举例讲解Ruby中迭代器Iterator的用法

ruby 迭代器使用方法

Ruby中相等性判断的4种方法

精品推荐
分类导航