Hi! Thanks for visiting my blog. If you've received any value from my content would you mind supporting my new startup by downloading our browser add-on? It's called PriceBlink and makes online shopping a breeze. You can watch it in action here and download it for Chrome, Firefox, IE, or Safari by going to PriceBlink.com. Thank you and I hope you enjoy!

No Multiline Comments With Ruby on Rails

Feb 28

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

3 comments

  1. Austin Mills /

    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 /

    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. 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!

Trackbacks/Pingbacks

  1. [db75] » Blog Archive » Using Multiline Comments With Ruby on Rails - [...] I recently posted that I was unsuccessful with multiline comments in Ruby on Rails.  It turns out that my ...
  2. Multiline Comments with Ruby - [...] Well, at least I wasn’t the only one. [...]

Leave a Reply