ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> ruby-talk
ruby-talk
Re: Class inheriting from class within the namespace
by Matt Neuburg other posts by this author
Oct 31 2006 9:21AM messages near this date
Class inheriting from class within the namespace | Re: Class inheriting from class within the namespace
Gavin Kistner <gavin.kistner@[...].com>  wrote:

>  Tree structures are interesting. Often the root of the tree is used as a
>  handle for the tree itself. However, the tree often has additional
>  methods beyond that of the root node.
>  
>  I couldn't figure out how to do this simply via inheritance due to
>  chicken-and-egg problems with namespacing:
>  
>    class Tree < Tree::Node
>      class Node
>      end
>    end
>    #=> chicken-and-egg.rb:1: uninitialized constant Tree (NameError)

Why wouldn't you do this?

module TreeStuff
  class Node
  end
  class Tree < Node
  end
end

A tree does more than a node (you say), so a tree is a subclass of node
("a node and then some"). The pair are wrapped up in a module to isolate
their namespace.

Of course I could be missing some other desideratum. m.

-- 
matt neuburg, phd = matt@[...].com, http://www.tidbits.com/matt/
Tiger - http://www.takecontrolbooks.com/tiger-customizing.html
AppleScript - http://www.amazon.com/gp/product/0596102119
Read TidBITS! It's free and smart. http://www.tidbits.com
Thread:
Gavin Kistner
Matt Neuburg
Gavin Kistner

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved