简体   繁体   中英

Block commenting in Ruby

Does Ruby have block comments?

If not, is there an efficient way of inserting # in front of a block of highlighted code in TextMate?

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.

在TextMate 2中,您可以⌘/注释掉当前行或选定的行。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM