<p>In Python, you can do this:</p>
<pre><code>print &quot;Hi!  I'm %(name)s, and I'm %(age)d years old.&quot; % ({&quot;name&quot;:&quot;Brian&quot;,&quot;age&quot;:30})
</code></pre>
<p>What's the closest, simplest Ruby idiom to replicate this behavior?  (No monkeypatching the String class, please.)</p>
<p>One of the really excellent benefits of this is that you can store the pre-processed string in a variable and use it as a &quot;template&quot;, like so:</p>
<pre><code>template = &quot;Hi!  I'm %(name)s, and I'm %(age)d years old.&quot;
def greet(template,name,age):
    print template % ({&quot;name&quot;:name,&quot;age&quot;:age})
</code></pre>
<p>This is obviously a trivial example, but there is a lot of utility in being able to store such a string for later use.  Ruby's <code>&quot;Hi!  I'm #{name}&quot;</code> convention is cursorily similar, but the immediate evaluation makes it less versatile.</p>

In a double-quoted string in Ruby, you can insert the result of a Ruby expression like this:
```
```
puts "Hi!  I'm #{name}, and I'm #{age} years old."
```
```
Just put an expression inside the curly braces. (It could also be something more complex like #{age + 5}, or #{name + ' ' + last_name}, or a function call.)