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.

ex8.rb

 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, second: false, third: true, fourth: false}  7    puts formatter % {first: formatter, second: formatter, ...

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.