I'm a little confused about when to use single quoted strings versus double quoted strings. I've noticed that if I put a variable inside a single quoted string, it doesn't get interpreted. Also, if I use a newline character in a double quoted string, it causes the string to be displayed over two lines whereas in a single quoted string the newline just appears as text within the string - the string is not displayed over two lines.
When it comes to backslashes, though, I'm not sure what's going on. If I add a backslash+space to the start of a string I get a different result:
"\ text"
'\ text'
In the output for the double quoted string I see only a space.
In the output for the single quoted string I see backslash+space.
What's happening there? Is this because the '\ ' is interpreted as a special character in the double quote string but in the single quoted string the characters are preserved as is?
If I change the strings to this, I see the same output, namely a single slash followed by a space and then the text:
"\\ text"
'\\ text'
In both cases the backslash is escaped. I'm confused why they work the same way in this situation.
Is there some basic rule that would help to explain the fundamental difference between how single quoted strings and double quoted strings handle backslashes in Ruby?