Skip to Main Content
Learn to Program, 2nd Edition
book

Learn to Program, 2nd Edition

by Chris Pine
March 2009
Intermediate to advanced content levelIntermediate to advanced
194 pages
4h
English
Pragmatic Bookshelf
Content preview from Learn to Program, 2nd Edition

Diversion: Double-Quoted Strings

So far, we’ve used only single-quoted strings. They are the easiest to use, in the same sense that a shovel is easier to use than a backhoe: when the job gets big enough, it stops being easier.

Consider multiline strings:

buffy_quote_1 = ​'​\'​Kiss rocks​\'​?
Why would anyone want to kiss...
Oh, wait. I get it.'
buffy_quote_2 = ​"'Kiss rocks'?​\n​"​ +
"Why would anyone want to kiss...​\n​"​ +
"Oh, wait. I get it."
puts buffy_quote_1
puts
puts(buffy_quote_1 == buffy_quote_2)
'Kiss rocks'?
Why would anyone want to kiss...
Oh, wait. I get it.
false

Using double quotes, we can indent the strings so they all line up. You’ll notice the “\n”, which is the escape sequence for the newline character. With this, you ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learn to Program, 3rd Edition

Learn to Program, 3rd Edition

Chris Pine
The Book of Ruby

The Book of Ruby

Huw Collingbourne

Publisher Resources

ISBN: 9781680500172Errata