title: How to quickly join two strings in Ruby
body: <p>It's common to need to join strings, and in Ruby we have common ways of doing it: appending, concatenating and interpolating one into the other, or using the built-in <code>concat</code> method in String. (We have multiple ways of doing it for flexibility and to ease the transition from other languages to Ruby.)</p>
  
  <p>Starting with:</p>
  
  <pre><code>'a ' &lt;&lt; 'z'      # =&gt; "a z"
  'a '.concat('z') # =&gt; "a z"
  'a ' + 'z'       # =&gt; "a z"
  "a #{'z'}"       # =&gt; "a z"
  </code></pre>
  
  <p>Assuming we don't want to change either string and that the strings won't be assigned to variables, what is the fastest way to join them, and does the fastest way change as the size of the "left" string grows?</p>
  
  <p>For those who can't figure out why we'd post questions like this, it's to help educate and show the most efficient way to do a particular task. Newcomers to a language, Ruby in this case, often drag old ways of doing something with them, and inadvertently write code that runs more slowly than necessary. A simple change to their coding style can result in faster code.</p>