Reputation: 887
So, I can have something like this (A):
module A
class B
end
end
and also I can have this (B):
class A::B
end
Why would I use A instead of B and vice versa?
Upvotes: 2
Views: 236
Reputation: 168081
When you are defining The second option saves indentation and is more compact, which is useful when you want to write something to A::B
for the first time, you have to take the first option. Otherwise,A::B
concisely and independent of other things in A
.
Upvotes: 1
Reputation: 5556
Because in option B module A must be already defined. There are also some other issues with this option. You can read more about it here http://techblog.thescore.com/how-you-nest-modules-matters-in-ruby/
Upvotes: 1