Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 字符串文字,无需转义反斜杠_Ruby_String_Literals - Fatal编程技术网

Ruby 字符串文字,无需转义反斜杠

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#中,我可以在字符串前使用
@
编写反斜杠和其他特殊字符,而无需转义,但我必须转义双引号

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"}