Reputation: 19727
Say I have the following double-quoted string in Ruby:
"Person's name"
Does the single quote need to be escaped?
Upvotes: 1
Views: 137
Reputation: 27845
Your test and the aother answers showed you already, that there is no difference.
p "Person's name"
p "Person\'s name"
With single quotes, it is a difference:
You get a syntax error with
p 'Person's name'
The quoted version will work:
p 'Person\'s name'
If this behaviour irritated you, perhaps you prefer another possibility to create a String:
p %{Person's name}
p %q{Person's name} #like '
p %Q{Person's name} #like "
Upvotes: 1
Reputation: 2983
The reverse holds true too. If I know i'm going to be using double quotes, i'll use single quotes to wrap my string in. However, it may be best to use double quotes at all times , if you use other languages, since single quotes usually just reference a character. It gets annoying modifying my c# code because I said var x = 'hello world';
Upvotes: 1