liveBook · Manning

Double-quoted string

As explained in The Well-Grounded Rubyist, Fourth Edition

A double-quoted string is a Ruby string literal delimited by double quotation marks that supports interpolation and escape processing.

A double-quoted string is a Ruby string literal enclosed in quotation marks. Unlike a single-quoted string, it evaluates #{...} interpolation and interprets escape sequences such as \n and \t. section 8.1.1

Interpolation versus literal text

puts "Two plus two is #{2 + 2}." outputs “Two plus two is 4.”; the single-quoted equivalent prints the interpolation markers literally. Escape interpolation with backslashes when the expression should remain text.

puts "Two plus two is #{2 + 2}."
puts 'Two plus two is #{2 + 2}.'

Compare interpolation evaluated inside double quotes with the same characters preserved inside single quotes. section 8.1.1

How The Well-Grounded Rubyist, Fourth Edition covers it

How deep it goes
Explains interpolation, escaped interpolation, quotation marks, backslashes, newlines, and tabs through runnable contrasts.
Examples
Demonstrates arithmetic interpolation, escaped interpolation, quotation marks, backslashes, newlines, and tab characters.
What it assumes
Assumes basic Ruby string literals and contrasts double quotes with single-quoted strings.
What you can do after
Apply double-quoted syntax to interpolate expressions and represent escaped characters in Ruby strings.
How it connects
Connects double-quoted strings with string literals, interpolation, escape sequences, and single-quoted strings.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Well-Grounded Rubyist, Fourth Edition. The section links point to the parts of the book it draws on.