Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Ruby comments


May 12, 2021 Ruby


Table of contents


Ruby comments

Comments are comment lines within Ruby code that are ignored at run time. A single-line comment starts with the character , until the line ends, as follows:

#!/usr/bin/ruby -w

This is a one-line comment.

puts "Hello, Ruby!"

Run an instance . . .


When executed, the above program produces the following results:

Hello, Ruby!

Ruby multi-line comments

You can comment on more than one line using the syntax of s begin and s end, as follows:

#!/usr/bin/ruby -w

puts "Hello, Ruby!"

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

When executed, the above program produces the following results:

Hello, Ruby!

Make sure that the comments at the end are enough distance from the code to make it easy to distinguish between comments and code. I f there is more than one tail comment in the block, align them. For example:

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