title: Rails Method_missing to throw back values from a hash
body: <p>i am trying to write a method_missing method, so that when i run a method it must hit the hash and look at the keys, if it finds a match to return the value. and continue. the hash is populated from a sql query that i wrote so the values are never constant. </p>
  
  <p>an example would be like </p>
  
  <pre><code> @month_id.number_of_white_envelopes_made
  </code></pre>
  
  <p>in the hash</p>
  
  <pre><code> @data_hash[number_of_white_envelopes_made] =&gt; 1
  </code></pre>
  
  <p>so @month_id will return 1. i have never worked with it before, not much material out there using hashes as the fall back with method missing </p>
  
  <p>EDIT: sorry i forgot to say if it doesnt find the method in the hash then it can continue down to no method error</p>
  
  <p>EDIT: alright so i was hacking away and this is what i have come up with</p>
  
  <pre><code> def method_missing(method)
     if @data_hash.has_key? method.to_sym
       return @data_hash[method]
     else
       super
     end
   end
  </code></pre>
  
  <p>is there a better way?</p>