Forum: Ruby Block comments syntax

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jonathan L. (Guest)
on 2005-12-25 13:54
(Received via mailing list)
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
Wybo D. (Guest)
on 2005-12-25 14:39
(Received via mailing list)
On Sun, 25 Dec 2005, Jonathan L. wrote:

> 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>
Johan Toki Persson (Guest)
on 2005-12-25 14:45
(Received via mailing list)
Make sure that you don't indent them...
Stefan L. (Guest)
on 2005-12-25 14:45
(Received via mailing list)
On Sunday 25 December 2005 12:53, Jonathan L. wrote:
> 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.
Jonathan L. (Guest)
on 2005-12-25 19:15
(Received via mailing list)
On Sun, 2005-12-25 at 21:45 +0900, Stefan L. 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?
Johan Toki Persson (Guest)
on 2005-12-25 22:10
(Received via mailing list)
More that it is a facility for embedded documentation:
http://www.ruby-doc.org/docs/ProgrammingRuby/html/...
mathew (Guest)
on 2005-12-28 06:23
(Received via mailing list)
Jonathan L. 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
Jonathan L. (Guest)
on 2005-12-28 15:22
(Received via mailing list)
On Wed, 2005-12-28 at 13:22 +0900, mathew wrote:
> Jonathan L. 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.
Eero S. (Guest)
on 2005-12-28 21:08
Jonathan L. wrote:
> On Wed, 2005-12-28 at 13:22 +0900, mathew wrote:
>> Jonathan L. 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
Shot - Piotr S. (Guest)
on 2005-12-30 15:43
(Received via mailing list)
Hello.

Jonathan L.:

> 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
This topic is locked and can not be replied to.