Possible Duplicate:
Which style of Ruby string quoting do you favour?
Is there a good rule of thumb about when to use single or double quotes in ruby, and especially rails apps?
Doesn't one use more memory than the other? Is there any sort of convention the rails community has settled on?
In JavaScript, single (' ') and double (“ ”) quotes are frequently used for creating a string literal. Generally, there is no difference between using double or single quotes, as both of them represent a string in the end.
The basic difference between these two methods is Single quotes can not hold/print escape sequences directly, while double quotes can. i.e. Double quoted strings are used for String Interpolation in Ruby.
General Usage Rules In America, Canada, Australia and New Zealand, the general rule is that double quotes are used to denote direct speech. Single quotes are used to enclose a quote within a quote, a quote within a headline, or a title within a quote.
The main difference between double quotes and single quotes is that by using double quotes, you can include variables directly within the string. It interprets the Escape sequences. Each variable will be replaced by its value.
The difference between using double quotes versus single quotes is that double quotes interpret escaped characters and single quotes preserve them.
Here is an example
puts "i \n love \n ruby"
#i
#love
#ruby
and
puts 'i \n love \n ruby'
#i \n love \n ruby
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With