Strings

Lesson 9 of 20

Quotes, interpolation and a toolbox of methods — bend text into any shape with Ruby's friendliest type.

The big picture

Working with words

Strings hold text — and Ruby gives them a toolbox of methods plus the elegant #{...} interpolation trick.

Quotes make strings

Single or double quotes both work — but only "..." interpolates.

Interpolation #{...}

Drops any Ruby expression straight into the text, results included.

Methods on tap

upcase, length, reverse and friends return brand-new strings.

Strings do math too

+ glues two strings together; * repeats one: "ha" * 3 is "hahaha".