title: In Ruby, is it possible to move a module up the ancestor chain?
body: <p>I have a Ruby class <code>C</code> that includes some third-party modules, say <code>A</code> and <code>B</code>.</p>
  
  <p>Module <code>A</code> is included indirectly via <code>C</code>'s class inheritance chain; assume I have no control over where <code>A</code> gets incuded. Now, <code>C</code> includes <code>B</code> directly, but <code>B</code> includes another module <code>D</code> which happens to provide functionality that is also provided by <code>A</code>, like this:</p>
  
  <pre><code>class C &lt; Base
  
    # Base includes A
  
    include B   # includes D
  
    # methods in A overridden by D
  
  end      
  </code></pre>
  
  <p>The ancestor chain goes something like this (where <code>...</code> represents zero or more other ancestors that aren't relevant to this discussion):</p>
  
  <pre><code>C ... B ... D ... A 
  </code></pre>
  
  <p>I want the functionality of <code>A</code> to take precdence over <code>D</code>: I want to move <code>A</code> so it is in front of <code>D</code> in the ancestor chain, like this:</p>
  
  <pre><code>C ... A ... B ... D
  </code></pre>
  
  <p>I have tried simply including <code>A</code> again but this didn't work. Is there a way to do this?</p>