title: How to add a method to an existing class in a gem?
body: <p>I'm trying to access a hash by using an regular class method like this:</p>
  
  <blockquote>
    <p>aHash.key</p>
  </blockquote>
  
  <p>But I get this error:</p>
  
  <blockquote>
    <p>undefined method `key1' for {:key1=>"value1", :key2=>"value2"}:Hash</p>
  </blockquote>
  
  <p>I defined a 'method_missing' in a Hash class as suggested <a href="http://www.intridea.com/blog/2007/8/7/bending-ruby-i-user-friendly-hashes-using-method_missing" rel="nofollow">here</a>:</p>
  
  <pre><code>class Hash
    def method_missing(method, *params)
      method = method.to_sym
      return self[method] if self.keys.collect(&amp;:to_sym).include?(method)
      super
    end
  end
  </code></pre>
  
  <p>I know for sure, that when I call 'aHash.key' it does not use the Hash I defined. If I look at one on my gems, it shows this:</p>
  
  <blockquote>
    <p>require "activerecord-postgres-hstore/hash"</p>
  </blockquote>
  
  <p>So I checked this file, and indeed they have implemented another hash. I believe I should add 'method_missing' in there but can it be done without modified the gem?</p>
  
  <p>Maybe I'm not getting how class overloading works with ruby, so the answer might be something else.</p>