O'Reilly logo

Learn Ruby the Hard Way: A Simple and Idiomatic Introduction to the Imaginative World of Computational Thinking with Code, Third Edition, Video Enhanced Edition by Zed A. Shaw

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Exercise 8. Printing, Printing

Image

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required