title: ruby 1.9 - what is easiest inverse of `string.codepoints.to_a`?
body: <p>In ruby 1.9.3, I can get the codepoints of a string:</p>
  
  <pre><code>&gt; "foo\u00f6".codepoints.to_a
   =&gt; [102, 111, 111, 246] 
  </code></pre>
  
  <p>Is there a built-in method to go the other direction, ie from integer array to string?</p>
  
  <p>I'm aware of:</p>
  
  <pre><code># not acceptable; only works with UTF-8
  [102, 111, 111, 246].pack("U*")
  
  # works, but not very elegant
  [102, 111, 111, 246].inject('') {|s, cp| s &lt;&lt; cp }
  
  # concise, but I need to unshift that pesky empty string to "prime" the inject call
  ['', 102, 111, 111, 246].inject(:&lt;&lt;)
  </code></pre>
  
  <p>UPDATE (response to Niklas' answer)</p>
  
  <p>Interesting discussion.
  <code>pack("U*")</code> always returns a UTF-8 string, while the <code>inject</code> version returns a string in the file's source encoding.</p>
  
  <pre><code>#!/usr/bin/env ruby
  # encoding: iso-8859-1
  
  p [102, 111, 111, 246].inject('', :&lt;&lt;).encoding
  p [102, 111, 111, 246].pack("U*").encoding
  # this raises an Encoding::CompatibilityError
  [102, 111, 111, 246].pack("U*") =~ /\xf6/
  </code></pre>
  
  <p>For me, the <code>inject</code> call returns an ISO-8859-1 string, while <code>pack</code> returns a UTF-8. To prevent the error, I could use <code>pack("U*").encode(__ENCODING__)</code> but that makes me do extra work.</p>
  
  <p>UPDATE 2</p>
  
  <p>Apparently the String#&lt;&lt; doesn't always append correctly depending on the string's encoding. So it looks like pack is still the best option.</p>
  
  <pre><code>[225].inject(''.encode('utf-16be'), :&lt;&lt;)  # fails miserably
  [225].pack("U*").encode('utf-16be')  # works
  </code></pre>