Formatted strings
suggest changeRuby can inject an array of values into a string by replacing any placeholders with the values from the supplied array.
"Hello %s, my name is %s!" % ['World', 'br3nt']
# => "Hello World, my name is br3nt!"
The placeholders are the two %s markers. The values come from ['World', 'br3nt']. % tells the string to substitute them. A named or positional format such as %{name} and %1$s is also available; this example uses the array form.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents