That is doing "interpolation". The value "replaced"
of the key :test
of the hash is inserted to the %{test}
position in the original string '%{test}'
.
The %
can take a string, array, or hash depending on the need. When you only have a single slot in the template as in this case, it is better to use %s
and pass a string like
"%s" % "replaced"
With the particular example, it is not useful.
It becomes useful when you want to replace a part of a string. For example, if you want to generate a series of strings:
"Hello World", "Hey World", "Bye World"
you can have a template string s = "%s World"
and interpolate things into it like
s % "Hello"
s % "Hey"
s % "Bye"