title: In Ruby, how do I make a hash from an array?
body: <p>I have a simple array:</p>
  
  <pre><code>arr = ["apples", "bananas", "coconuts", "watermelons"]
  </code></pre>
  
  <p>I also have a function <code>f</code> that will perform an operation on a single string input and return a value. This operation is very expensive, so I would like to memoize the results in the hash.</p>
  
  <p>I know I can make the desired hash with something like this:</p>
  
  <pre><code>h = {}
  arr.each { |a| h[a] = f(a) }
  </code></pre>
  
  <p>What I'd like to do is not have to initialize h, so that I can just write something like this:</p>
  
  <pre><code>h = arr.(???) { |a| a =&gt; f(a) }
  </code></pre>
  
  <p>Can that be done?</p>