From: gwtmp01@... Date: 2006-07-15T03:05:59+09:00 Subject: Re: Don't understand :: in ActionController::Base On Jul 14, 2006, at 9:13 AM, P�l Bergstr�m wrote: > I understand the concept of classes and subclasses thanks to the > excellent "Programming Ruby - The Pragmatic Programmer's Guide". > However, I don't understand what :: signify in terms of inheritance, > parent and child in e.g. This seems to be a common source of confusion when learning Ruby (myself included). It is really pretty simple. Class and Module objects are referenced via hierarchical names: A A::B ActionController::Base ActiveRecord::Base Process::Sys The confusion arises when you assume that the names imply class/subclass relationships. The hierarchy of *names* is 100% independent of the hierarchy of classes. The scope operator (::) provides the syntax for constructing the hierarchical class names but has no impact on the inheritance structure of the classes: class A class A1; end end class B class B1; end end class C < A; end class D < A::A1; end class E < B::B1; end class B::B1::B2 < A::A1; end class A::A1::A2 < B::B1::B2; end From those definitions you get the following inheritance structure: Object + -- A --------- C | + -- A::A1 --+-- D | | | +-- B::B1::B2 -- A::A1::A2 | + -- B | + -- B::B1 ----- E The associated naming hierarchy is top + -- A -- A1 -- A2 | + -- B -- B1 -- B2 | + -- C | + -- D | + -- E Gary Wright