# Including modules - ordering question

**URL:** <https://www.ruby-forum.com/t/including-modules-ordering-question/107894>\
**Category:** Ruby\
**Created:** [June 27, 2007, 6:36am UTC](https://www.ruby-forum.com/t/including-modules-ordering-question/107894 "2007-06-27T06:36:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ericgoodwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c68b51/32.png) [@ericgoodwin](https://www.ruby-forum.com/u/ericgoodwin)\
**Post date:** [June 27, 2007, 6:36am UTC](https://www.ruby-forum.com/t/including-modules-ordering-question/107894/1 "2007-06-27T06:36:33Z")

</div>

Hi,

I have a module where I include modules as usual:

module A  
module B  
end  
module C  
include B  
include D  
end  
module D  
end

end

When I require this file, I’ll get an error here because module D is  
being included before it gets loaded. I would need to put it above  
module C to get it to work. How can I load the file, and then do all the  
includes so that it can actually find the module.

---

<div class="post-metadata">

**Author:** ![ericgoodwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c68b51/32.png) [@ericgoodwin](https://www.ruby-forum.com/u/ericgoodwin)\
**Post date:** [June 27, 2007, 7:39am UTC](https://www.ruby-forum.com/t/including-modules-ordering-question/107894/2 "2007-06-27T07:39:18Z")

</div>

On 27 Jun 2007, at 13:36, Aryk G. wrote:

> end  
> module D  
> end
> 
> end
> 
> When I require this file, I’ll get an error here because module D is  
> being included before it gets loaded. I would need to put it above  
> module C to get it to work. How can I load the file, and then do  
> all the  
> includes so that it can actually find the module.

Perhaps I’m missing something, but haven’t you answered your own  
question…

> I would need to put it above module C to get it to work.

So the structure of the file should look like this:

> module A  
> module B  
> end  
> module D  
> end  
> module C  
> include B  
> include D  
> end  
> end

Perhaps there is something more complicated going on in your example  
that I am not understanding?

Alex G.

Bioinformatics Center  
Kyoto University

---

<div class="post-metadata">

**Author:** ![ericgoodwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c68b51/32.png) [@ericgoodwin](https://www.ruby-forum.com/u/ericgoodwin)\
**Post date:** [June 27, 2007, 11:21am UTC](https://www.ruby-forum.com/t/including-modules-ordering-question/107894/3 "2007-06-27T11:21:37Z")

</div>

Le 27 juin à 06:36, Aryk G. a écrit :

> When I require this file, I’ll get an error here because module D is  
> being included before it gets loaded. I would need to put it above  
> module C to get it to work. How can I load the file, and then do all the  
> includes so that it can actually find the module.

Not sure how (if) it would work, but can’t you just define an empty  
Module D with “module D ; end” and then reopen it after :

module A  
module B  
# code  
end  
module D ; end  
module C  
include B  
include D  
# code  
end  
module D  
# code  
end  
end

Fred

---

<div class="post-metadata">

**Author:** ![ericgoodwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c68b51/32.png) [@ericgoodwin](https://www.ruby-forum.com/u/ericgoodwin)\
**Post date:** [June 27, 2007, 7:21pm UTC](https://www.ruby-forum.com/t/including-modules-ordering-question/107894/4 "2007-06-27T19:21:37Z")

</div>

Well, basically Im looking for a solution where order doesn’t matter.  
Hmm, I wonder if that trick with the module would work. It’s kind of  
hacky. Wonder if there is a better way or maybe you just have to be  
aware of order all the time.
