title: Elegant way to add to_hash (or to_h) method to Struct?
body: <p>I'm using a Struct as opposed to a simple Hash in a project to provide a semantic name to a collection of key value pairs.  Once I've built the structure, however, I need to output a hash value.  I'm in Ruby 1.9.3. Example:</p>
  
  <pre><code>MyMeaninfulName = Struct.new(:alpha, :beta, :gamma) do
    def to_hash
      self.members.inject({}) {|h,m| h[m] = self[m]; h}
    end
  end
  
  my_var = MyMeaningfulName.new
  my_var.to_hash # -&gt; { :alpha=&gt;nil, :beta=&gt;nil, :gamma=&gt;nil } 
  </code></pre>
  
  <p>Is there a reason why Struct does not include a to_hash method?  It seems like a natural fit, but perhaps there's an underlying reason why it's not included.  </p>
  
  <p>Second, is there a more elegant way to build a generic to_hash method into Struct (either generally, via monkeypatching, or through a module or inheritance).</p>