Ruby 字符串文字,无需转义反斜杠
在C#中,我可以在字符串前使用Ruby 字符串文字,无需转义反斜杠,ruby,string,literals,Ruby,String,Literals,在C#中,我可以在字符串前使用@编写反斜杠和其他特殊字符,而无需转义,但我必须转义双引号 C# 在Ruby中,我可以使用单引号字符串文字,但我希望将其与字符串插值结合使用,如“text#{value}”。Ruby中是否有与C#中的@等价的东西?Ruby中也有类似的东西。例如 foo = %Q(The integer division operator in VisualBASIC is written "a \\ b" and #{'interpolation' + ' works'}) 还可
@
编写反斜杠和其他特殊字符,而无需转义,但我必须转义双引号
C#
在Ruby中,我可以使用单引号字符串文字,但我希望将其与字符串插值结合使用,如
“text#{value}”
。Ruby中是否有与C#中的@
等价的东西?Ruby中也有类似的东西。例如
foo = %Q(The integer division operator in VisualBASIC is written "a \\ b" and #{'interpolation' + ' works'})
还可以在其中插入字符串。唯一需要注意的是,您仍然需要转义\
字符
HTH您可以将herdeoc与单引号一起使用
foo = <<'_'
The integer division operator in VisualBASIC is written "a \ b";
_
您需要使用“\”进行预编,Rails中没有等效项。您不清楚需要什么。Ruby中的单引号字符串文字仍然需要转义反斜杠。您仍然需要转义“\`”(反斜杠)AFAIK。
foo=您可以在herdoc的开头标识符之后调用chomp
,即foo=是否有办法避免转义反斜杠?
foo = <<'_'
The integer division operator in VisualBASIC is written "a \ b";
_
foo = <<'_'
text %{value}
_
foo.chomp % {value: "foo"}