Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Block comments syntax

Reply
Thread Tools

Block comments syntax

 
 
Jonathan Leighton
Guest
Posts: n/a
 
      12-25-2005
Hello,

It says at http://www.rubygarden.org/ruby?RubyFromC 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://turnipspatch.com/ | http://jonathanleighton.com/ | http://digital-proof.org/



 
Reply With Quote
 
 
 
 
Wybo Dekker
Guest
Posts: n/a
 
      12-25-2005
On Sun, 25 Dec 2005, Jonathan Leighton wrote:

> Hello,
>
> It says at http://www.rubygarden.org/ruby?RubyFromC 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?


I don't see an error:

wybo>cat t
=begin
my comment
=end
puts 'hello'
wybo>ruby t
hello
wybo>ruby -v
ruby 1.8.4 (2005-10-29) [i686-linux]
wybo>

--
Wybo


 
Reply With Quote
 
 
 
 
Johan Toki Persson
Guest
Posts: n/a
 
      12-25-2005
Make sure that you don't indent them...

 
Reply With Quote
 
Stefan Lang
Guest
Posts: n/a
 
      12-25-2005
On Sunday 25 December 2005 12:53, Jonathan Leighton wrote:
> Hello,
>
> It says at http://www.rubygarden.org/ruby?RubyFromC 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


 
Reply With Quote
 
Jonathan Leighton
Guest
Posts: n/a
 
      12-25-2005
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://turnipspatch.com/ | http://jonathanleighton.com/ | http://digital-proof.org/



 
Reply With Quote
 
Johan Toki Persson
Guest
Posts: n/a
 
      12-25-2005
More that it is a facility for embedded documentation:
http://www.ruby-doc.org/docs/Program...ml/rdtool.html

 
Reply With Quote
 
Jonathan Leighton
Guest
Posts: n/a
 
      12-28-2005
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://turnipspatch.com/ | http://jonathanleighton.com/ | http://digital-proof.org/



 
Reply With Quote
 
Eero Saynatkari
Guest
Posts: n/a
 
      12-28-2005
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-forum.com/.


 
Reply With Quote
 
Shot - Piotr Szotkowski
Guest
Posts: n/a
 
      12-30-2005
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/hovercraft/ === http://shot.pl/1/125/ ===


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fo:Block can you check to see if a block contains any text by using the block id? morrell XML 1 10-10-2006 07:18 PM
A program to replace all JS comments with JSP comments in jsp files tungchau81@yahoo.com Javascript 4 06-03-2006 02:00 PM
A program to replace all JS comments with JSP comments in jsp files tungchau81@yahoo.com Java 0 06-02-2006 06:35 AM
Comments format: comments extending over multi-line Monk C Programming 10 04-20-2005 05:09 PM



Advertisments