How can I preserve / maintain consecutive newlines in Ruby here-document?

跟風遠走 提交于 2019-12-24 22:28:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!