title: Convert a class to a subclass on instantiation
body: <p>I'm writing a framework for querying the <a href="http://www.mediawiki.org/wiki/API" rel="nofollow noreferrer">Mediawiki API</a>. I have a <code>Page</code> class which represents articles on the wiki, and I've also got a <code>Category</code> class, which <em>is-a</em> <code>Page</code> with more specific methods (like being able to count the number of members in the category. I've also got a method <code>Page#category?</code> which determines if an instantiated <code>Page</code> object is actually representative of a Mediawiki category page, by querying the API to determine the namespace of the article.</p>
  
  <pre><code>class Page
    def initialize(title)
      # do initialization stuff
    end
  
    def category?
      # query the API to get the namespace of the page and then...
      namespace == CATEGORY_NAMESPACE
    end
  end
  
  class Category &lt; Page
    # ...
  end
  </code></pre>
  
  <p>What I would like to do is be able to detect if the user of my framework tries to instantiate a Mediawiki category using a Page object (ie. <code>Page.new("Category:My Category")</code>), and if so, instantiate a <code>Category</code> object, instead of a <code>Page</code> object, directly from the <code>Page</code> constructor.</p>
  
  <p>It seems to me that this should be possible because it's reminiscent of single table inheritance in Rails, but I'm not sure how to go about getting it to work.</p>