99

Does Ruby have block comments?

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

Timur Shtatland
  • 12,024
  • 2
  • 30
  • 47
alamodey
  • 14,320
  • 24
  • 86
  • 112

4 Answers4

202

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

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Garry Shutler
  • 32,260
  • 12
  • 84
  • 119
  • 2
    One thing to note is that you must have the "Source" bundle enabled for the CMD + / shortcut to work. I had disabled it at some point in the past during an overzealous bundle purging rage and couldn't figure out why my Mac kept beeping at me whenever I tried using the comment shortcut. – Chris Bloom Jun 11 '12 at 15:09
  • Could be worth mentioning that Command + / also block comments in Sublime Text too – Adam Waite May 26 '13 at 20:24
  • it goes wrong if there is some <% %> open tags in the block of commented code. Maybe there is any other way to do this? – Gediminas Šukys Jun 12 '13 at 19:21
  • Even better, they must be the only thing in their line. If you write something after "=begin" you get "syntax error, unexpected '=', expecting keyword_end" – Nemo Jan 13 '15 at 17:34
23

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.

Andrew Hare
  • 344,730
  • 71
  • 640
  • 635
2

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.

Andrew
  • 4,145
  • 2
  • 37
  • 42
  • Yeah. Notepad++ lets you do this by holding alt as well (e.g. alt-shift-up arrow several times); UltraEdit and other editors have "column mode" as well. – AlexC Mar 08 '13 at 14:49
0

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

Torsten
  • 425
  • 4
  • 7