title: Unique on an array of hashes based on value
body: <p>I feel like this could be improved (a common feeling in ruby).  I'm trying to uniq an array of hashes based on value.  In this example, I want the colors of the elements.  Moss and snow are impostors.</p>
  
  <pre><code># remove unique array of hashes based on a hash value
  
  a = [
    { :color =&gt; "blue", :name =&gt; "water" },
    { :color =&gt; "red", :name =&gt; "fire" },
    { :color =&gt; "white", :name =&gt; "wind" },
    { :color =&gt; "green", :name =&gt; "earth" },
    { :color =&gt; "green", :name =&gt; "moss" },
    { :color =&gt; "white", :name =&gt; "snow" }
  ]
  
  # remove moss and snow
  uniques = []
  a.each_with_index do |r, i|
    colors = uniques.collect {|e| e[:color]}
  
    if !colors.include? r[:color]
      uniques.push r
    else
      a[i] = nil
    end
  end
  
  a.compact!
  
  puts a
  </code></pre>
  
  <p>This will print</p>
  
  <pre><code>{:color=&gt;"blue", :name=&gt;"water"}
  {:color=&gt;"red", :name=&gt;"fire"}
  {:color=&gt;"white", :name=&gt;"wind"}
  {:color=&gt;"green", :name=&gt;"earth"}
  </code></pre>
  
  <p>Which is "correct" however I feel like this is excessive.  My experience with .map .inject is limited and those advanced techniques elude me.  If someone could re-factor this, it might help me understand another terse technique.</p>