title: Factory methods in Ruby
body: <p><strong>What is the slickest, most Ruby-like way to have a single constructor return an object of the appropriate type?</strong></p>
  
  <p>To be more specific, here's a dummy example: say I have two classes <code>Bike</code> and <code>Car</code> which subclass <code>Vehicle</code>. I want this:</p>
  
  <pre><code>Vehicle.new('mountain bike')  # returns Bike.new('mountain bike')
  Vehicle.new('ferrari')        # returns Car.new('ferrari')
  </code></pre>
  
  <p>I've proposed a solution below, but it uses <code>allocate</code> which seems way too implementation-heavy. What are some other approaches, or is mine actually ok?</p>