在 Ruby 中可以像 PHP 的 nowdoc [1] 那样使用多行字符串
例如
puts '
\\foo
'
我想输出如下没有转义的
\\foo
[1] Nowdocs 之于单引号字符串就像 heredocs 之于双引号字符串。 nowdoc 的指定类似于 heredoc,但在 nowdoc 内部不进行任何解析。 http://hk1.php.net/manual/en/language.types.string.php#language.types.string.syntax.nowdoc
最佳答案
如 literals documentation 中所述,您只需要在 heredoc 标识符周围加上单引号,如下所示:
puts <<'EOS'
#{variable}
\\escaped
EOS
输出:
#{variable}
\\escaped
关于像 PHP nowdoc 这样的 Ruby 多行字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21991797/