[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Ruby Namespaces / Modules

eastcoastcoder

3/10/2006 12:10:00 AM

If I'm in the middle of module A::B::C, and I want to reference a class
from A::B or from A::B::D, do I need to do ::A::B::Classname (or
::A::B::D::Classname)?

It seems a bit repititous to me. A module shouldn't need to know it's
ancestors all the way up - just what it needs to use. Having to keep
track couples modules to a tree and obstructs refactoring.

So, what say the veteran Rubyists?

1 Answer

MenTaLguY

3/10/2006 12:25:00 AM

0

Quoting eastcoastcoder@gmail.com:

> If I'm in the middle of module A::B::C, and I want to reference a
> class from A::B or from A::B::D, do I need to
> do ::A::B::Classname (or ::A::B::D::Classname)?
>
> It seems a bit repititous to me. A module shouldn't need to know
> it's ancestors all the way up - just what it needs to use.
> Having to keep track couples modules to a tree and obstructs
> refactoring.
>
> So, what say the veteran Rubyists?

Try it!

module A
module B
class Foo
end
module D
class Bar
end
end
end
module C
p B::Foo
p B::D::Bar
end
end

-mental