Block comments syntax

Discussion in 'Ruby' started by Jonathan Leighton, Dec 25, 2005.

  1. Jonathan Leighton, Dec 25, 2005
    #1
    1. Advertising

  2. Jonathan Leighton

    Wybo Dekker Guest

    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
    Wybo Dekker, Dec 25, 2005
    #2
    1. Advertising

  3. Make sure that you don't indent them...
    Johan Toki Persson, Dec 25, 2005
    #3
  4. Jonathan Leighton

    Stefan Lang Guest

    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
    Stefan Lang, Dec 25, 2005
    #4
  5. 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/
    Jonathan Leighton, Dec 25, 2005
    #5
  6. Johan Toki Persson, Dec 25, 2005
    #6
  7. 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/
    Jonathan Leighton, Dec 28, 2005
    #7
  8. 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/.
    Eero Saynatkari, Dec 28, 2005
    #8
  9. 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/ ===
    Shot - Piotr Szotkowski, Dec 30, 2005
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,095
  2. John Salerno

    why no block comments in Python?

    John Salerno, Mar 8, 2006, in forum: Python
    Replies:
    18
    Views:
    39,674
    Roy Smith
    Mar 11, 2006
  3. morrell
    Replies:
    1
    Views:
    936
    roy axenov
    Oct 10, 2006
  4. Monk
    Replies:
    10
    Views:
    1,439
    Michael Wojcik
    Apr 20, 2005
  5. Replies:
    4
    Views:
    576
    Dr John Stockton
    Jun 3, 2006
Loading...

Share This Page