title: Get Ruby class constant dynamically by name
body: <p>I have a class API that pulls objects from a third party API and builds them into objects that are subclasses of type <code>APIObject</code>.  <code>APIObject</code> subclasses match the object names from the API that I'm pulling from:</p>
  
  <pre><code>User &lt; APIObject
  Account &lt; APIObject
  </code></pre>
  
  <p>I would like to define a class method in APIObject that allows me to pull objects using standard Rails accessors:</p>
  
  <pre><code>user = User.find id
  </code></pre>
  
  <p>I would like the method to translate this call into an API call like this:</p>
  
  <pre><code>API::User::findById id
  </code></pre>
  
  <p>I would like to access the name of the APIObject subclass (<code>User</code>) using <code>self.class.name</code> and use that to call the constant (<code>API::User</code>), but I know <code>API::self.class.name</code> won't work.  I could rewrite this method over and over again for every subclass, but it seems like this should be possible without doing that.  Suggestions?</p>