array of here documents

Discussion in 'Ruby' started by Roger Pack, Feb 8, 2008.

  1. Roger Pack

    Roger Pack Guest

    Question: is it possible to create an array of here documents?
    a = [<<END
    some stuff
    more stuff
    END,
    <<END
    even more
    END
    ]

    ?
     
    Roger Pack, Feb 8, 2008
    #1
    1. Advertisements

  2. Roger Pack

    Phrogz Guest

    stuff = [ <<DOC1, <<DOC2, <<DOC3 ]
    Hello World
    DOC1
    How's it going?
    DOC2
    It's just crazy, thanks.
    DOC3

    p stuff
    #=> ["Hello World\n", "How's it going?\n", "It's just crazy, thanks.
    \n"]
     
    Phrogz, Feb 8, 2008
    #2
    1. Advertisements

  3. Roger Pack

    Xavier Noria Guest

    Yup:

    a = [<<FOO, <<BAR]
    some stuff
    more stuff
    FOO
    even more
    BAR
     
    Xavier Noria, Feb 8, 2008
    #3
  4. Roger Pack

    Roger Pack Guest

    Gavin Kistner wrote:
    Posted by Xavier Noria (fxn) on 09.02.2008 00:19
    Thanks.
     
    Roger Pack, Feb 8, 2008
    #4
  5. Roger Pack

    Adam Shelly Guest

    I'm glad I didn't have to write the parser for that....
     
    Adam Shelly, Feb 9, 2008
    #5
  6. Waste of constants / variables.

    robert
     
    Robert Klemme, Feb 9, 2008
    #6
  7. Roger Pack

    Xavier Noria Guest

    Well, we are not advocating here documents in a row, we are just
    answering a technical question about whether is possible to have them
    that way.
     
    Xavier Noria, Feb 9, 2008
    #7
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.