Ruby 中是否有任何单行字符串文字语法允许字符串插值但不将反斜杠解释为转义字符?
IE,
在哪里ruby_var = "foo"
我希望能够键入相当于C:\some\windows\path\#{ruby_var}\path
生成字符串的内容C:\some\windows\path\foo\path
,而不必转义反斜杠或求助于多行heredoc。
puts "C:\some\windows\path\#{ruby_var}\path"
puts "C:\some\windows\path\path_#{ruby_var}\path"
=> C: omewindowspath#{ruby_var}path
=> C: omewindowspathpath_foopath
puts 'C:\some\windows\path\#{ruby_var}\path'
puts 'C:\some\windows\path\path_#{ruby_var}\path'
=> C:\some\windows\path\#{ruby_var}\path
=> C:\some\windows\path\path_#{ruby_var}\path
puts %{C:\some\windows\path\#{ruby_var}\path}
puts %{C:\some\windows\path\path_#{ruby_var}\path}
=> C: omewindowspath#{ruby_var}path
=> C: omewindowspathpath_foopath
puts %q{C:\some\windows\path\#{ruby_var}\path}
puts %q{C:\some\windows\path\path_#{ruby_var}\path}
=> C:\some\windows\path\#{ruby_var}\path
=> C:\some\windows\path\path_#{ruby_var}\path