# "How Classes and Objects Interact" (Pickaxe)

**URL:** <https://www.ruby-forum.com/t/how-classes-and-objects-interact-pickaxe/120244>\
**Category:** Ruby\
**Created:** [November 15, 2007, 3:27am UTC](https://www.ruby-forum.com/t/how-classes-and-objects-interact-pickaxe/120244 "2007-11-15T03:27:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [November 15, 2007, 3:27am UTC](https://www.ruby-forum.com/t/how-classes-and-objects-interact-pickaxe/120244/1 "2007-11-15T03:27:26Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [November 15, 2007, 10:43pm UTC](https://www.ruby-forum.com/t/how-classes-and-objects-interact-pickaxe/120244/2 "2007-11-15T22:43:09Z")

</div>

Greg W. 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.
