Ruby comments


Comments are commented lines within Ruby code that are ignored at runtime. Single-line comments begin with the # character and continue until the end of the line, as follows:

Instance

#!/usr/bin/ruby -w

# 这是一个单行注释。

puts "Hello, Ruby!"

Run Example»

Click the "Run Instance" button to view the online instance

When executed, the above program will produce the following results:

Hello, Ruby!

Ruby multi-line comments

You can Comment multiple lines using the =begin and =end syntax, as shown below:

#!/usr/bin/ruby -w

puts "Hello, Ruby!"

=begin
这是一个多行注释。
可扩展至任意数量的行。
但 =begin 和 =end 只能出现在第一行和最后一行。 
=end

When executed, the above program produces the following results:

Hello, Ruby!

Please make sure that the comments at the end are far enough away from the code to make it easy to distinguish the comments from the code. If there is more than one comment at the end, align them. For example:

@counter      # 跟踪页面被点击的次数
@siteCounter  # 跟踪所有页面被点击的次数