问题
I wonder how can I preserve consecutive newline characters with Ruby here-document? In my program all of them are collapsed to one newline. For example:
s=<<END
1
2
3
4
END
evaluates to:
s="1\n2\n3\n4\n"
However I would like to preserve the consecutive newlines when for example formatting a BBcode document a letter or something similar.
回答1:
That looks like a bug to me. Have you tried a multiline %q
?
s=%q(1
2
3
4
)
来源:https://stackoverflow.com/questions/18157087/how-can-i-preserve-maintain-consecutive-newlines-in-ruby-here-document