如何在Ruby here-document中保存/维护连续的换行符? [英] How can I preserve / maintain consecutive newlines in Ruby here-document?

查看:75
本文介绍了如何在Ruby here-document中保存/维护连续的换行符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何使用Ruby here-document保留连续的换行符?在我的程序中,它们全部都折叠为一个换行符.例如:

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

评估为:

s="1\n2\n3\n4\n"

但是,例如在格式化BBcode文档的字母或类似格式时,我想保留连续的换行符.

However I would like to preserve the consecutive newlines when for example formatting a BBcode document a letter or something similar.

推荐答案

对我来说,这似乎是个错误.您是否尝试过多行%q?

That looks like a bug to me. Have you tried a multiline %q?

s=%q(1
2

3


4



)

这篇关于如何在Ruby here-document中保存/维护连续的换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆