Ruby 中的块注释

Ruby 有块注释吗?

如果没有,是否有一种有效的方法来插入 #在一块突出显示的代码在 TextMate?

68149 次浏览

You can do

=begin
[Multi line comment]
=end

=begin and =end must be at the beginning of the line (not indented at all).

Source

Also, in TextMate you can press Command + / to toggle regular comments on a highlighted block of code.

Source

Ruby has documentation comments - they look like this:

=begin
...
=end

Not perfect but they get the job done in a pinch.

[Edit] It is important to note that =begin and =end must be at the beginning of their respective lines.

In TextMate, you can alt-drag vertically to select a column of text. This will duplicate the insertion point across all the lines you select, so you can insert or delete multiple #s at once.

UPDATE: Also in TextMate, assuming you have the right language selected, Cmd + / will toggle commenting every line in a selection regardless of language.

In TextMate 2 you can ⌘/ to comment out the current line or selected lines.