title: Two way lookup of id vs name ruby
body: <p>I have a hash in which <code>id</code> is the key and <code>name</code> is the value. Both <code>id and value are unique</code>. </p>
  
  <p>Something like this:</p>
  
  <pre><code>h[1] = "ABC"
  h[3] = "DEF"
  </code></pre>
  
  <p>So, if I am given the key of 1, I can easily return a value "ABC".</p>
  
  <p>I need to do a <code>reverse lookup</code> as well, which means if I am given a value of "DEF", I should return 3.</p>
  
  <p>Also, instead of a single value or single key to do the lookup,  <br>
  I may be provided with an array of values or array of keys instead. </p>
  
  <p>Should I implement two hashes, one for each, or is there any other way in ruby or rails to achieve that?</p>
  
  <p><strong>Edit:</strong> This question is <strong>not related to finding a key by its value</strong> in a hash. It is related to doing a two way lookup not in O(n) time with a better method other than creating two separate hashes. </p>