19

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?

Community
  • 1
  • 1
Lee McAlilly
  • 9,084
  • 12
  • 60
  • 94
  • Also, a dup of [When to use single vs. double quotes in a Rails app](http://stackoverflow.com/questions/1836467/is-there-a-performance-gain-in-using-single-quotes-vs-double-quotes-in-ruby). I try to use single unless I'm interpolating. – Brian Deterling Feb 11 '11 at 04:26
  • This is generally a good question but has been answered several times on this site. – Michael Papile Feb 11 '11 at 04:42
  • Thanks for chiming in. I didn't find those threads on the site earlier ; ) – Lee McAlilly Feb 11 '11 at 17:51

1 Answers1

56

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
Mahesh
  • 6,378
  • 2
  • 26
  • 35