Don't understand :: in ActionController::Base

  • Thread starter PÃ¥l Bergström
  • Start date
P

Pål Bergström

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.

ActionController::Base
 
P

Pål Bergström

Pål Bergström said:
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.

ActionController::Base

Btw, I'm told that I can find the answer in chapter 9, starting at page
117. But I read it on the web at
http://www.ruby-doc.org/docs/ProgrammingRuby/, so I have no chapters.
 
D

dblack

---2049402039-421898782-1152882940=:30407
Content-Type: MULTIPART/MIXED; BOUNDARY="-2049402039-421898782-1152882940=:30407"

This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.

---2049402039-421898782-1152882940=:30407
Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed
Content-Transfer-Encoding: QUOTED-PRINTABLE

Hi --

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.

ActionController::Base

See my reply on the Rails list :)


David

--=20
http://www.rubypowerandlight.com =3D> Ruby/Rails training & consultancy
http://www.manning.com/black =3D> RUBY FOR RAILS (reviewed on
Slashdot, 7/12/2006!)
http://dablog.rubypal.com =3D> D[avid ]A[. ]B[lack's][ Web]log
(e-mail address removed) =3D> me
---2049402039-421898782-1152882940=:30407--
---2049402039-421898782-1152882940=:30407--
 
J

Jeff Pritchard

Hi PÃ¥l,
I'm a newbie too. I'll stick my neck out and answer here just so as to
"trick" an expert into answering. Once they see my miserable excuse for
an answer, they will be honor bound to correct me :)

ActionController::Base refers to the "Base" class of the Module
ActionController. So you are not "inheriting" the whole module, just
the "Base" class of the module. Makes sense for a Class to inherit a
Class definition rather than a whole module's definition.

best,
jp
 
L

Logan Capaldo

Hi P=E5l,
I'm a newbie too. I'll stick my neck out and answer here just so =20
as to
"trick" an expert into answering. Once they see my miserable =20
excuse for
an answer, they will be honor bound to correct me :)

ActionController::Base refers to the "Base" class of the Module
ActionController. So you are not "inheriting" the whole module, just
the "Base" class of the module. Makes sense for a Class to inherit a
Class definition rather than a whole module's definition.

best,
jp

Everything but sentence was perfect. You can't inherit modules.

(Please avoid top posting in the future).
 
G

gwtmp01

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

=46rom 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
 
P

Pål Bergström

Jeff said:
Hi PÃ¥l,
I'm a newbie too. I'll stick my neck out and answer here just so as to
"trick" an expert into answering. Once they see my miserable excuse for
an answer, they will be honor bound to correct me :)

ActionController::Base refers to the "Base" class of the Module
ActionController. So you are not "inheriting" the whole module, just
the "Base" class of the module. Makes sense for a Class to inherit a
Class definition rather than a whole module's definition.


Thanks for the effort Jeff. A good trick :)
 
P

Pål Bergström

unknown said:
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.
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


Thanks. That helped.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top