Sunday, July 28, 2013

Ruby - strings - difference between using single quotes & double quotes


https://rubymonk.com/learning/books/1-ruby-primer/chapters/5-strings/lessons/31-string-basics
A String literal created with single quotes does not support interpolation.
The essential difference between using single or double quotes is that double quotes allow for escape sequences while single quotes do not. What you saw above is one such example. “\n” is interpreted as a new line and appears as a new line when rendered to the user, whereas '\n' displays the actual escape sequence to the user.
Example of interpolation:
a = 1
b = 4
puts "The number #{a} is less than #{b}" 

No comments:

Post a Comment

Followers

Blog Archive