"How Classes and Objects Interact" (Pickaxe)

G

Greg Weeks

I'm sorry about the bandwidth, but I just read "How Classes and Objects
Interact" from Chapter 24 ("Classes and Objects") of the Pickaxe book,
and I *have* to comment that it is so clear that it hurts. I hate to
cut into book sales, but that section should be readily available --
diagrams and all -- on the web. Is it?

The grey box, "Metaclasses and Singleton Classes", was of special
interest. Matz is quoted as saying that the class <<Foo -- as in
"class <<Foo ... end" -- is "not a class of a class; it's a singleton
class of a class." Hmmm:

class Foo
class <<Foo
p (Foo.is_a? self) # true, and
p (self.is_a? Class) # true, but
p (Foo.class == self) # false
end
end

The ".class" call above returns a *named* class, rather than the
anonymous (or "virtual") class that, in the underlying implementation,
actually holds Foo (and only Foo). Whew!

In any case, I've seen nothing even approaching the clarity of the
Pickaxe text.

PS: In my recent exposure to Ruby, I've become so addicted to poetry
mode that I'd rather write

p (Foo.is_a? self)
than:
p Foo.is_a?(self)

Indeed, I originally omitted the parentheses entirely and was not
pleased to be warned to "parenthesize argument(s) for future version".
I'm definitely being corrupted.

PS: For anyone who thinks that this newbie (me) has been posting too
much recently: I'M GOING TO TRY TO STOP!
 
G

Greg Weeks

Greg said:
PS: For anyone who thinks that this newbie (me) has been posting too
much recently: I'M GOING TO TRY TO STOP!

And I will. But first:

Many people wonder: Why doesn't module inclusion include class methods?
Perhaps this will help: Inclusions are for *modules*, and the class
methods of a module belong to a *class*:

class C
class <<M
MetaM = self
class <<C
include MetaM # wrong argument type Class (expected Module)
end
end
end

Duh-oh! Anyway, this makes me happy with the existing behavior.
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top