Block commenting in Ruby
Asked Answered
R

4

101

Does Ruby have block comments?

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

Receptor answered 11/2, 2009 at 13:28 Comment(2)
In Emacs, you can press Meta-; to comment / uncomment a selected region.Billowy
Possible duplicate of Multi-Line Comments in Ruby?Slatternly
P
203

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

Point answered 11/2, 2009 at 13:31 Comment(4)
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.Gape
Could be worth mentioning that Command + / also block comments in Sublime Text tooDisunion
it goes wrong if there is some <% %> open tags in the block of commented code. Maybe there is any other way to do this?Fete
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"Acierate
W
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.

Wandawander answered 11/2, 2009 at 13:32 Comment(0)
D
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.

Distraint answered 19/1, 2013 at 2:0 Comment(1)
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.Threedecker
F
0

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

Filipino answered 15/4, 2015 at 7:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.