[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

block commenting-out

newyorkdolluk

8/14/2006 1:51:00 PM

hi,

can anyone tell me how to bulk comment-out lines of code rather than
#'ing each line?

thanks

21 Answers

Robert Klemme

8/14/2006 1:58:00 PM

0

On 14.08.2006 15:51, newyorkdolluk wrote:
> hi,
>
> can anyone tell me how to bulk comment-out lines of code rather than
> #'ing each line?
>
> thanks
>

15:56:48 [~]: ruby <<XXX
> puts 1
> =begin
> foo
> adha sdjas dha dad +asdp+adp+ad+
> =end
> puts 2
> XXX
1
2

In short, use "=begin" and "=end".

Kind regards

robert

Francis Cianfrocca

8/14/2006 2:01:00 PM

0

On 8/14/06, newyorkdolluk <all@itgiant.co.uk> wrote:
> hi,
>
> can anyone tell me how to bulk comment-out lines of code rather than
> #'ing each line?
>
> thanks
>
>
>


=begin

your code

=end

I have to know, how does a New York Doll end up in the UK?

Farrel Lifson

8/14/2006 2:01:00 PM

0

On 14/08/06, newyorkdolluk <all@itgiant.co.uk> wrote:
> hi,
>
> can anyone tell me how to bulk comment-out lines of code rather than
> #'ing each line?
>
> thanks
>
>
>

=begin
This is a comment
on multiple lines
=end

Farrel

Jeff Schwab

8/14/2006 2:05:00 PM

0

newyorkdolluk wrote:

> can anyone tell me how to bulk comment-out lines of code rather than
> #'ing each line?

I don't think there's a multi-line comment character, although I'm sure
someone on this list will come up with a neat hack. At the very least,
you could embed the code in a string:

def begin_comment(s)
# Ignore it. It's a comment.
end

begin_comment <<end_comment # Comment until end of comment.
This is a string that's actually serving
as a multi-line comment.
end_comment

If you're using vim, though:

Go to the beginning of the first line to be commented.
Hit ^V to begin block selection.
Use j to get down to the last line to be commented.
Enter capital I to begin inserting.
Enter #, since it's the Ruby comment character.
Hit Esc.

Ken Bloom

8/14/2006 11:47:00 PM

0

On Mon, 14 Aug 2006 14:05:11 +0000, Jeffrey Schwab wrote:

> newyorkdolluk wrote:
>
>> can anyone tell me how to bulk comment-out lines of code rather than
>> #'ing each line?
>
> I don't think there's a multi-line comment character, although I'm sure
> someone on this list will come up with a neat hack. At the very least,
> you could embed the code in a string:
>
> def begin_comment(s)
> # Ignore it. It's a comment.
> end
>
> begin_comment <<end_comment # Comment until end of comment.
> This is a string that's actually serving
> as a multi-line comment.
> end_comment
>
> If you're using vim, though:
>
> Go to the beginning of the first line to be commented.
> Hit ^V to begin block selection.
> Use j to get down to the last line to be commented.
> Enter capital I to begin inserting.
> Enter #, since it's the Ruby comment character.
> Hit Esc.

If you're going to take this approach (and =begin =end is probably better)
then there's no need to define a method. simply use a heredoc that won't
get used:

<<end_comment
The comment started with the previous line

and ends when the heredoc ends
end_comment

Of course, this won't work correctly as the last line in a method, so use
(=begin...=end) as other posters have described.

--Ken

--
Ken Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu...

Jeff Schwab

8/15/2006 4:43:00 AM

0

Ken Bloom wrote:
> On Mon, 14 Aug 2006 14:05:11 +0000, Jeffrey Schwab wrote:

>> def begin_comment(s)
>> # Ignore it. It's a comment.
>> end
>>
>> begin_comment <<end_comment # Comment until end of comment.
>> This is a string that's actually serving
>> as a multi-line comment.
>> end_comment

> If you're going to take this approach (and =begin =end is probably better)
> then there's no need to define a method. simply use a heredoc that won't
> get used:
>
> <<end_comment
> The comment started with the previous line
>
> and ends when the heredoc ends
> end_comment

That generates a nasty warning:
main.rb:1: warning: useless use of a literal in void context

> Of course, this won't work correctly as the last line in a method, so use

Good point.

> (=begin...=end) as other posters have described.

Or, if at all feasible, actually comment each line.

Gene Tani

8/15/2006 6:42:00 AM

0


newyorkdolluk wrote:
> hi,
>
> can anyone tell me how to bulk comment-out lines of code rather than
> #'ing each line?
>
> thanks

Komodo can do block commenting out, prepending "#". Scite prepends
"##" so you know that is was done in bulk fashion. Your editor must
hvae something of the sort to block comment and uncomment.


Chad Perrin

8/15/2006 7:53:00 AM

0

On Tue, Aug 15, 2006 at 03:42:20PM +0900, Gene Tani wrote:
>
> newyorkdolluk wrote:
> > hi,
> >
> > can anyone tell me how to bulk comment-out lines of code rather than
> > #'ing each line?
> >
> > thanks
>
> Komodo can do block commenting out, prepending "#". Scite prepends
> "##" so you know that is was done in bulk fashion. Your editor must
> hvae something of the sort to block comment and uncomment.

Vim could, of course, do it via a substitution iterating over a number
of lines indicated by a prepended number. I'm sure EMACS (Esc Meta Alt
Ctrl Shift) could do something similar, but with four times as many keys
involved.

What, me biased? Never.

--
CCD CopyWrite Chad Perrin [ http://ccd.ap... ]
"There comes a time in the history of any project when it becomes necessary
to shoot the engineers and begin production." - MacUser, November 1990

Matt Todd

8/15/2006 8:00:00 AM

0

If you highlight the lines you want commented out in Textmate, then
press Command + /, it will prepend # to every line. It works quite
well. Plus, if you highlight and Command + / again, it'll remove the
#s.

;)

M.T.

Huw Collingbourne

8/15/2006 9:35:00 AM

0

With Ruby In Steel you just mark a block and click a button to comment or
uncomment ;-)

best wishes
Huw Collingbourne

http://www.sapphir...
Ruby Programming In Visual Studio 2005