Exercise 8. Printing, Printing


I will now show you how to create a format string, but rather than using variables, we’ll use values by their names. Some of this is a bit more advanced, but don’t worry you’ll learn what all of these mean later. Just type this in, make it work, and write a comment above each line translating it to English.


 1    formatter = "%{first} %{second} %{third} %{fourth}"  2  3    puts formatter % {first: 1, second: 2, third: 3, fourth: 4}  4    puts formatter % {first: "one", second: "two", third: "three",  5                      fourth: "four"}  6    puts formatter % {first: true, ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.