Block commenting in Ruby

RubyCommentsKeyboard ShortcutsText EditorBlock Comments

Ruby Problem Overview


Does Ruby have block comments?

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

Ruby Solutions


Solution 1 - Ruby

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

Solution 2 - Ruby

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.

Solution 3 - Ruby

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.

Solution 4 - Ruby

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionalamodeyView Question on Stackoverflow
Solution 1 - RubyGarry ShutlerView Answer on Stackoverflow
Solution 2 - RubyAndrew HareView Answer on Stackoverflow
Solution 3 - RubyAndrewView Answer on Stackoverflow
Solution 4 - RubyTorstenView Answer on Stackoverflow