# How to include multiple nested modules?

**URL:** <https://www.ruby-forum.com/t/how-to-include-multiple-nested-modules/209080>\
**Category:** Ruby\
**Created:** [July 5, 2011, 11:49am UTC](https://www.ruby-forum.com/t/how-to-include-multiple-nested-modules/209080 "2011-07-05T11:49:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [July 5, 2011, 11:49am UTC](https://www.ruby-forum.com/t/how-to-include-multiple-nested-modules/209080/1 "2011-07-05T11:49:20Z")

</div>

Hi everyone, I need help with a special request. I have a boot file that  
require all the files and also have a begin function that is executed  
before running all my other files. This function can now be called at  
any time in my code. But it is dynamically referencing other libraries I  
have and mixins and modules in that library. So at the moment I am  
trying to include nested modules like this:

require\_files ‘whitelabel’  
include Pages::WhiteLabel::Community  
include Pages::WhiteLabel::Games  
include Pages::WhiteLabel::GettingStarted  
include Pages::WhiteLabel::HelpFaq  
include Pages::WhiteLabel::Home  
include Pages::WhiteLabel::MyAccount  
include Pages::WhiteLabel::Promotions  
include Pages::WhiteLabel::Registration  
include Pages::WhiteLabel::ShopOfJoy  
include Pages::WhiteLabel::Vip  
include Pages::WhiteLabel::Winners  
include Pages::WhiteLabel::Magnolia  
include Pages::WhiteLabel::Mixins

Now, my question is, without creating a separate file that reference  
these modules, is it possible to do an “include” by doing a loop or  
calling the Pages::Whitelabel module to get access to all the submodules  
classes and methods?

---

<div class="post-metadata">

**Author:** ![mattias\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/74df32/32.png) [@mattias\_k](https://www.ruby-forum.com/u/mattias_k)\
**Post date:** [July 5, 2011, 12:06pm UTC](https://www.ruby-forum.com/t/how-to-include-multiple-nested-modules/209080/2 "2011-07-05T12:06:02Z")

</div>

its possable with this:

[:Community,:Games,:GettingStarted,:HelpFaq,:Home,:MyAccount,:Promotions,:Registration,:ShopOfJoy,:Vip,:Winners,:Magnolia,:Mixins].each  
do |s|  
include Pages::WhiteLabel.const\_get(s)  
end

or more dynamic:

Pages::WhiteLabel.constants.each do |s|  
m= Pages::WhiteLabel.const\_get(s)  
if(m.instance\_of?(Module))  
include m  
end  
end

---

<div class="post-metadata">

**Author:** ![mattias\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/74df32/32.png) [@mattias\_k](https://www.ruby-forum.com/u/mattias_k)\
**Post date:** [July 5, 2011, 12:47pm UTC](https://www.ruby-forum.com/t/how-to-include-multiple-nested-modules/209080/3 "2011-07-05T12:47:18Z")

</div>

Thank you very much, that worked perfectly 🙂
