Module/class question

Are these two below the same thing?

  1. module X
    module Y
    class Z

  2. class X::Y::Z

On 14 April 2010 01:45, Me [email protected] 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

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

OK, that is what I thought, thanks.

On 14 April 2010 15:18, Chris H. [email protected] 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