# Re: Class inheriting from class within the namespace

**URL:** <https://www.ruby-forum.com/t/re-class-inheriting-from-class-within-the-namespace/74598>\
**Category:** Ruby\
**Created:** [November 7, 2006, 10:49am UTC](https://www.ruby-forum.com/t/re-class-inheriting-from-class-within-the-namespace/74598 "2006-11-07T10:49:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [November 7, 2006, 10:49am UTC](https://www.ruby-forum.com/t/re-class-inheriting-from-class-within-the-namespace/74598/1 "2006-11-07T10:49:34Z")

</div>

From: matt neuburg [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]

> Why wouldn’t you do this?
> 
> module TreeStuff  
> class Node  
> end  
> class Tree \< Node  
> end  
> end

Only because it’s an annoying namespace level that the user would need  
to either repeatedly specify or include. If I wrap all my own classes in  
a Phrogz namespace, then the user needs to type:  
tree = Phrogz::TreeStuff::Tree.new  
and that’s a little ugly IMHO. If a class can serve as its own  
namespace, I think that it makes sense, to let it do so.

I also prefer to place subordinate/helper classes inside the class that  
they augment. To my way of thinking, it makes little sense to use a  
TreeStuff::Node outside of the context of a TreeStuff::Tree. As such, I  
would prefer to see that implicit dependency suggested by letting the  
Tree wrap its big old arms around the Node and say “MINE!”.

But you raise a good point; that’s certainly a good, simple way to  
achieve the goal without spewing classes about willy-nilly.
