I have an input that looks like \\some\windows\location that I need to pass down to a Ruby command.

Is there some way to stop the ruby compiler from interpreting it? On passing the above mentioned input, I see that the string has been stored as \some\windows\location

Also, it converts \\some\new\location to \some\\new\location

C# has a @ operator that makes sure that the string is passed as is, is there something like that for ruby? I'd like to achieve this without changing my ruby code much.

ADD
The user input comes from a c# console app, and I want to do minimal work on the input string to make it work with Ruby. What I want is to pass it down from my c# app to the ruby app and make it work.

You should be a bit more specific where you "have" your input string. If it is stored within a ruby String ruby will not tamper with it, but if you put this string into your source code it will inevitably interpret some of your backslashes. So please be specific: where do you get it from (and in what form) and where will it have to go to?
–
PatruJun 16 '14 at 6:35

1 Answer
1

If you want to create a string with a single backslash in Ruby you have to write \\, because the backslash is an escape character. Note, that a single backslash will be shown as "\\" by a REPL such as IRB or Pry. However, if you puts that string, you will only see a single backslash, which is the actual content of the string. You can see the escaped version when you do puts string.inspect or simply p string, which is the same.