title: get index from an array of hashes
body: <p>I am populating an array of hashes from the database and what I get in the end looks like:</p>
  
  <pre><code>[{:element1 =&gt; "value1", :element2 =&gt; "value2"}, {:element1 =&gt; "value3", :element2 =&gt; "value4"}]
  </code></pre>
  
  <p>What I want to do now is write the value of element2 if element1 has value1. I tried doing</p>
  
  <pre><code>puts my_array[my_array.index(:element1 =&gt; "value1")].element2
  </code></pre>
  
  <p>but that only gives me an error saying:</p>
  
  <pre><code>no implicit conversion from nil to integer
  </code></pre>
  
  <p>What I am using now is</p>
  
  <pre><code>puts my_array.find_by_element1("value1").element2
  </code></pre>
  
  <p>but that queries the database every time and I would like to avoid that if possible since I already have all the values.</p>
  
  <p>Edit: my Ruby version is 1.8.7</p>