array of here documents

R

Roger Pack

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

?
 
P

Phrogz

Question: is it possible to create an array of here documents?

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"]
 
X

Xavier Noria

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


?

Yup:

a = [<<FOO, <<BAR]
some stuff
more stuff
FOO
even more
BAR
 
R

Roger Pack

Gavin Kistner wrote:
Posted by Xavier Noria (fxn) on 09.02.2008 00:19
Question: is it possible to create an array of here documents?

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"]

Thanks.
 
A

Adam Shelly

Question: is it possible to create an array of here documents?

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

I'm glad I didn't have to write the parser for that....
 
R

Robert Klemme

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


?
Yup:

a = [<<FOO, <<BAR]
some stuff
more stuff
FOO
even more
BAR

Is there any reason you wouldn't set up the heredocs first and then add
them to an array?

HD1 = <<ENDHD1
This is a heredoc.
The first of 2.
ENDHD1

HD2 = <<ENDHD2
This is the second heredoc.
ie the last.
ENDHD2

a=[HD1,HD2]

Waste of constants / variables.

robert
 
X

Xavier Noria

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


?

Yup:

a = [<<FOO, <<BAR]
some stuff
more stuff
FOO
even more
BAR

Is there any reason you wouldn't set up the heredocs first and then
add
them to an array?

HD1 = <<ENDHD1
This is a heredoc.
The first of 2.
ENDHD1

HD2 = <<ENDHD2
This is the second heredoc.
ie the last.
ENDHD2

a=[HD1,HD2]

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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top