No Multiline Comments With Ruby on Rails



I’ve searched all over for this one and if you have any insight I’d love to hear it. It turns out there’s no support for multiline comments with Ruby on Rails. I guess I should say that this isn’t even supported in plain Ruby.

A general method for debugging that I use is to comment out chunks of code. This allows me to focus on a piece of code that might be causing a problem. While the exclusion of multiline comments isn’t a major issue, I’ll definitely need to look into alternate debugging techniques. While I realize a single comment (#) can be placed on every line, in some cases this may not be practical. For more information on Ruby feel free to check out this great reference:


Programming Ruby: The Pragmatic Programmers’ Guide, Second Edition



5 Responses to “No Multiline Comments With Ruby on Rails”

  1. Austin Mills says:

    Any decent Ruby editor should allow you to highlight a section of code and use a shortcut to comment it all out. For example, using Eclipse with the Ruby Development Tools plugin, Ctrl-/ will comment the highlighted section of code. Ctrl-/ on already commented code will undo the commenting.

  2. Golly says:

    You can also do use =begin and =end

    =begin
    multiple lines now
    commented out
    yay.
    =end

    These keywords must be at the beginning of a line and are actually for internal documentation but they do the trick :)

  3. dennis says:

    Thanks for the reply. I had actually tried that in the past and didn’t have much success. I realized after reading your comment that I should try actually using =begin and =end without any indentation. This did the trick and thanks for pointing their usage!

  4. [...] I recently posted that I was unsuccessful with multiline comments in Ruby on Rails.  It turns out that my usage was a little off and thanks to Golly for pointing this out.  I read previously about using =begin and =end to start and end multiline comments.  This didn’t work until I tried using these at the start of the line (as Golly suggested).  So your comment would end up looking like: [...]

  5. [...] Well, at least I wasn’t the only one. [...]

Leave a Reply