How to make Ruby ignore backslash in strings?

Is there any way in Ruby, I can avoid the need to use double backslash in Ruby strings (for example, what can be done in C #):

For example, in C # there may be a prefix for string c @, and then the backslash in the string does not need to be escaped:

@"C:\Windows, C:\ABC"

Without @us, we will need to avoid the backslash:

"C:\\Windows, C:\\ABC"

Is there something similar in Ruby?

+3
source share
2 answers

Use single quotes

my_string = 'C:\Windows'

More details in the "Lines" section here

+7
source

You can also use% q, and the backslash will be automatically escaped for you:

%q{C:\Windows} => "C:\\Windows"
+1
source

Source: https://habr.com/ru/post/1784212/