# Module/class question

**URL:** <https://www.ruby-forum.com/t/module-class-question/186905>\
**Category:** Rails\
**Created:** [April 14, 2010, 2:46am UTC](https://www.ruby-forum.com/t/module-class-question/186905 "2010-04-14T02:46:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [April 14, 2010, 2:46am UTC](https://www.ruby-forum.com/t/module-class-question/186905/1 "2010-04-14T02:46:29Z")

</div>

Are these two below the same thing?

1. module X  
module Y  
class Z

2. class X::Y::Z

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [April 14, 2010, 9:37am UTC](https://www.ruby-forum.com/t/module-class-question/186905/2 "2010-04-14T09:37:23Z")

</div>

On 14 April 2010 01:45, Me [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Are these two below the same thing?
> 
> 1. module X  
> module Y  
> class Z
> 
> 2. class X::Y::Z

Providing class Z has already been created with style 1, yes.

If you try to run style 2 without X and Y having been created you will  
get  
“NameError: uninitialized constant X”.

The difference between class and module in Ruby is fairly minimal (and  
mainly used for inferring a difference in usage to the reader)

Cheers,

Andy

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [April 14, 2010, 4:21pm UTC](https://www.ruby-forum.com/t/module-class-question/186905/3 "2010-04-14T16:21:19Z")

</div>

ok as far as controllers are concerned in a RoR app would either of  
those  
style matter as far as name spacing?

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [April 14, 2010, 4:37pm UTC](https://www.ruby-forum.com/t/module-class-question/186905/4 "2010-04-14T16:37:08Z")

</div>

OK, that is what I thought, thanks.

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [April 14, 2010, 4:35pm UTC](https://www.ruby-forum.com/t/module-class-question/186905/5 "2010-04-14T16:35:23Z")

</div>

On 14 April 2010 15:18, Chris H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ok as far as controllers are concerned in a RoR app would either of those  
> style matter as far as name spacing?

Nope, won’t matter a jot.

But if you have this:

class Admin::FooController

end

without declaring Admin first you’ll get an error.

What I tend to do is this:

module Admin  
class BaseController  
def some\_admin\_method  
…  
end  
end  
end

Because you need to declare Admin before you can just randomly start  
using  
it. Then I do this when declaring a subclass:

class PagesController \< Admin::BaseController  
…  
end

Cheers,

Andy
