Brian Mitchell
3/16/2005 10:44:00 PM
On Thu, 17 Mar 2005 07:19:41 +0900, David Tran <email55555@gmail.com> wrote:
> My question is how can you construct a "heredoc array" ( or hash).
>
> Let me start with is code:
> a = [
> 1,
> 2
> ]
>
> it is perfect ruby syntax.
>
> but if you put the ',' on next line like:
> a = [
> 1
> ,
> 2
> ]
> then you got syntax error.
>
> It seems stupid to put ',' on next line but I have no choice,
> here is my use case with heredoc example:
> a = [
> <<EOD1
> abc
> very very long string and many many lines ...
> EOD1
> ,
> <<EOD2
> 123
> very very long string and many many lines ...
> EOD2
> ]
>
> I cannot put the ',' just after EOD1, it must to the next line,
> if not, the "EOD1," is not consider termination of heredoc.
> but put the ',' on next line then I got syntax error ...
>
> How do you resolve this problem?
>
> Thank you.
>
>
Depending on what the test is, a %Q{ } pair might work better. You
will have to escape any '}'.
a = [
%Q{Multi line
white space is kept.
My here doc clone "can have quotes" 'of' any kind.},
%Q{just remember to use a \} to close
your text}
]
Personally, I don't care for heredoc format so i don't use it often.
Brian.