title: When is it better to use a Struct rather than a Hash in Ruby?
body: <p>A Ruby Struct allows an instance to be generated with a set of accessors:</p>
  
  <pre><code># Create a structure named by its constant
  Customer = Struct.new(:name, :address)     #=&gt; Customer
  Customer.new("Dave", "123 Main")           #=&gt; #&lt;Customer name="Dave", address="123 Main"&gt;
  </code></pre>
  
  <p>This looks convenient and powerful, however, a Hash does something pretty similar:</p>
  
  <pre><code>Customer = {:name =&gt; "Dave", :address =&gt; "123 Main"}
  </code></pre>
  
  <p>What are the real-world situations where I should prefer a Struct (and why), and what are the caveats or pitfalls in choosing one over the other?</p>