"How Classes and Objects Interact" (Pickaxe)

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!

···

--
Posted via http://www.ruby-forum.com/.

Greg Weeks wrote:

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.

···

--
Posted via http://www.ruby-forum.com/\.