Exercise 6. Strings and Text

While you have been writing strings, you still do not know what they do. In this exercise we create a bunch of variables with complex strings so you can see what they are for. First, we need an explanation of strings.

A string is usually a bit of text you want to display to someone, or “export” out of the program you are writing. Ruby knows you want something to be a string when you put either " (double-quotes) or ' (single-quotes) around the text. You saw this many times with your use of puts, when you put the text you want to go into the string inside " after the puts to print the string.

Strings can contain any number of variables that are in your Ruby script. Remember that a variable is any line of code where ...

Get Learn Ruby the Hard Way: A Simple and Idiomatic Introduction to the Imaginative World of Computational Thinking with Code, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.