[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Block comments syntax

Jonathan Leighton

12/25/2005 11:53:00 AM

Hello,

It says at http://www.rubygarden.org/ruby... that I can do block
comment in Ruby like so:

=begin
my comment
=end

However, when I try to I get a syntax error. Why is this? How can I do
it?

Many Thanks

--
Jonathan Leighton
http://turnips... | http://jonathanlei... | http://digital-...



9 Answers

Wybo Dekker

12/25/2005 12:37:00 PM

0

Toki

12/25/2005 12:41:00 PM

0

Make sure that you don't indent them...

Stefan Lang

12/25/2005 12:45:00 PM

0

On Sunday 25 December 2005 12:53, Jonathan Leighton wrote:
> Hello,
>
> It says at http://www.rubygarden.org/ruby... that I can do
> block comment in Ruby like so:
>
> =begin
> my comment
> =end
>
> However, when I try to I get a syntax error. Why is this? How can I
> do it?

Two notes, since the RubyGarden page doesn't mention it:

* Ensure that there is no space/tab before =begin and
=end (i.e. the = must be the first character in the line)

* Nesting of =begin/=end blocks is not possible.

--
Stefan


Jonathan Leighton

12/25/2005 5:15:00 PM

0

On Sun, 2005-12-25 at 21:45 +0900, Stefan Lang wrote:
> * Ensure that there is no space/tab before =begin and
> =end (i.e. the = must be the first character in the line)

This was it, thanks all.

Incidentally, the =begin and =end syntax seems pretty cumbersome to me
(compared to /* */ for instance). Is it like this because Ruby is so
versatile and anything else would be difficult to parse?

--
Jonathan Leighton
http://turnips... | http://jonathanlei... | http://digital-...



Toki

12/25/2005 8:04:00 PM

0

More that it is a facility for embedded documentation:
http://www.ruby-doc.org/docs/ProgrammingRuby/html/r...

mathew

12/28/2005 4:21:00 AM

0

Jonathan Leighton wrote:
> Incidentally, the =begin and =end syntax seems pretty cumbersome to me
> (compared to /* */ for instance). Is it like this because Ruby is so
> versatile and anything else would be difficult to parse?

Maybe it's like that because it's a facility you're not supposed to use;
many people feel block comments are a bad idea. Personally, I only use
them in languages which lack line comments.


mathew
--
<URL:http://www.pobox.com/...
My parents went to the lost kingdom of Hyrule
and all I got was this lousy triforce.

Jonathan Leighton

12/28/2005 1:20:00 PM

0

On Wed, 2005-12-28 at 13:22 +0900, mathew wrote:
> Jonathan Leighton wrote:
> > Incidentally, the =begin and =end syntax seems pretty cumbersome to me
> > (compared to /* */ for instance). Is it like this because Ruby is so
> > versatile and anything else would be difficult to parse?
>
> Maybe it's like that because it's a facility you're not supposed to use;
> many people feel block comments are a bad idea. Personally, I only use
> them in languages which lack line comments.

Well if you want to temporarily get rid of a large number of lines,
block comments are much, much quicker than doing a line comment for each
and every line. I don't tend to leave block comments in the app though
-- just during development I find them useful.

--
Jonathan Leighton
http://turnips... | http://jonathanlei... | http://digital-...



Eero Saynatkari

12/28/2005 7:08:00 PM

0

Jonathan Leighton wrote:
> On Wed, 2005-12-28 at 13:22 +0900, mathew wrote:
>> Jonathan Leighton wrote:
>> > Incidentally, the =begin and =end syntax seems pretty cumbersome to me
>> > (compared to /* */ for instance). Is it like this because Ruby is so
>> > versatile and anything else would be difficult to parse?
>>
>> Maybe it's like that because it's a facility you're not supposed to use;
>> many people feel block comments are a bad idea. Personally, I only use
>> them in languages which lack line comments.
>
> Well if you want to temporarily get rid of a large number of lines,
> block comments are much, much quicker than doing a line comment for each
> and every line. I don't tend to leave block comments in the app though
> -- just during development I find them useful.

Perhaps.

V10n:s/^/#/

Comments out the next ten lines for me. I could alias
it to a macro key but I have not bothered yet :)


E

--
Posted via http://www.ruby-....


Shot - Piotr Szotkowski

12/30/2005 1:42:00 PM

0

Hello.

Jonathan Leighton:

> Well if you want to temporarily get rid of a large number of lines,
> block comments are much, much quicker than doing a line comment for
> each and every line.

In vim, I simply use block select (ctrl-v) to select the first column
of the affected lines and replace the spaces with comment marks (r#).
This has the additional benefit of not shifting the commented-out code
to the right.

Cheers,
-- Shot
--
In the UNIX world, people tend to interpret 'non-technical user' as meaning
someone who's only ever written one device driver. -- Daniel Pead
====================== http://shot.pl/h... === http://shot... ===