multi-line strings with """

N

Navindra Umanee

Hi,

Why is it that multi-line strings that begin with """ close themselves
when a single " is encountered?

irb(main):006:0> """
irb(main):007:0" This is a multi-line string
irb(main):008:0" with a "
=> "\nThis is a multi-line string\nwith a "

I find this to be somewhat annoying. The Python way seems preferable:
... In this string I can have isolated "s without worry
... the only way to end the string is with """
'\nIn this string I can have isolated "s without worry\nthe only way to end thestring is with '

Any chance this behavior will change in the next Ruby? :)

Thanks,
Navin.
 
Y

YANAGAWA Kazuhisa

In Message-Id: <[email protected]>
Navindra Umanee said:
Why is it that multi-line strings that begin with """ close themselves
when a single " is encountered?

irb(main):006:0> """
irb(main):007:0" This is a multi-line string
irb(main):008:0" with a "
=> "\nThis is a multi-line string\nwith a "

1. multiple string literals are concatenated.
2. There're no multi-line string specific quotations.

In the above case your string is parsed as "" and "\nThis...." in a
sequence.

Any chance this behavior will change in the next Ruby? :)

You can use:

"mere single double-quotation
for multi-line string"

str = <<EOS
or use here document
for multi-line string
EOS
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top