Learn Ruby the Hard Way
by Zed Shaw
# the variable formatter is being assigned a series of 4 string formatters
# that will take 4 arguments
formatter = "%s %s %s %s"
# the method puts prints the variable formatter; using string
# interpolation it prints the arguments of integers that follow
puts formatter % [1,2,3,4]
# the method puts prints the variable formatter; using string
# interpolation it prints the arguments of 4 strings that follow
puts formatter % ["one","two","three","four"]
# the method puts prints the variable formatter; using string
# interpolation it prints the arguments of 4 boolean values that follow
puts formatter % [true, false, false, true]
# the method puts prints the variable formatter; using string
# interpolation it prints the arguments of 4 variables of itself
puts formatter % [formatter, formatter, formatter, formatter]
# the method puts prints the variable formatter; using string
# interpolation it prints the arguments of 4 strings that follow
puts formatter % [
"I had this thing.",
"That you could type up right.",
"But it didn't sing.",
"So I said goodnight."
]
# the method puts prints the variable formatter; using string
# interpolation it prints the arguments of itsel, a boolean value,
# a strings and an integer that follow
puts formatter % [ formatter, true, "But it didn't sing.", 4]