title: How to dynamically alter inheritance in Ruby
body: <p>I would like to dynamically specify the parent class for a class in Ruby.  Consider this code:</p>
  
  <pre><code>class Agent
    def self.hook_up(calling_class, desired_parent_class)
      # Do some magic here
    end
  end
  
  class Parent
    def bar
      puts "bar"
    end
  end
  
  class Child
    def foo
      puts "foo"
    end
  
    Agent.hook_up(self, Parent)
  end
  
  Child.new.bar
  </code></pre>
  
  <p>Neither the <code>Parent</code> nor the <code>Child</code> class definition specifies a parent class, so they both inherit from Object.  My first question is: what would I need to do in <code>Agent.hook_up</code> in order to make <code>Parent</code> the superclass of <code>Child</code> (so for example <code>Child</code> objects can inherit the 'bar' method).</p>
  
  <p>My second question is: do I <em>need</em> to pass the first argument to <code>Agent.hook_up</code>, or is there some way the <code>hook_up</code> method can programmatically determine the class from which it was called?</p>