Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi-Line Comments in Ruby?

How can I comment multiple lines in Ruby?

like image 949
Mohit Jain Avatar asked Jun 07 '10 13:06

Mohit Jain


People also ask

How do you comment multiple lines in Ruby?

Multi-Line Comments A multi-line comment begins with the =begin token and ends with the =end token. These tokens should start at the beginning of the line and be the only thing on the line. Anything between these two tokens is ignored by the Ruby interpreter. lines are ignored by the Ruby interpreter.

How do you comment multiple lines at once?

To comment out multiple code lines right-click and select Source > Add Block Comment. ( CTRL+SHIFT+/ )


2 Answers

#!/usr/bin/env ruby  =begin Every body mentioned this way to have multiline comments.  The =begin and =end must be at the beginning of the line or it will be a syntax error. =end  puts "Hello world!"  <<-DOC Also, you could create a docstring. which... DOC  puts "Hello world!"  "..is kinda ugly and creates a String instance, but I know one guy with a Smalltalk background, who does this."  puts "Hello world!"  ## # most # people # do # this   __END__  But all forgot there is another option. Only at the end of a file, of course. 
  • This is how it looks (via screenshot) - otherwise it's hard to interpret how the above comments will look. Click to Zoom-in:

Comments in a text-editor

like image 172
Konstantin Haase Avatar answered Sep 22 '22 09:09

Konstantin Haase


=begin My  multiline comment here =end 
like image 34
Adam Lear Avatar answered Sep 22 '22 09:09

Adam Lear