title: Dynamically define named classes in Ruby
body: <p>I am writing an internal DSL in Ruby.  For this, I need to programmatically create named classes and nested classes.  What is the best way to do so?  I recon that there are two ways to do so:</p>
  
  <ol>
  <li>Use <code>Class.new</code> to create an anonymous class, then use <code>define_method</code> to add methods to it, and finally call <code>const_set</code> to add them as named constants to some namespace.</li>
  <li>Use some sort of <code>eval</code></li>
  </ol>
  
  <p>I've tested the first way and it worked, but being new to Ruby, I am not sure that putting classes as constants is the right way.</p>
  
  <p>Are there other, better ways?  If not, which of the above is preferable?</p>