Hi --

On Sun, 1 Feb 2009, Sean O'Halpin wrote:

> On Sun, Feb 1, 2009 at 12:03 PM, David A. Black <dblack / rubypal.com> wrote:
>>
>> They're related conceptually but they also fit into the object model
>> nicely: every method is defined in a class or module; every object has
>> a lookup path of classes and modules. I know Matz has said that the
>> main thrust of per-object behavior is per-object behavior, and that
>> the way it's implemented (singleton class, which, like other classes,
>> can include modules) is secondary, but there's a tremendous advantage
>> to having it blend into the overall landscape
>
> I agree. After all, subclasses lookup class methods in a parent
> class's singleton class and clones inherit from an instance's, e.g.
>
> class A
>  def self.foo
>    "foo"
>  end
> end
> class B < A
> end
> a = A.new
> def a.foo
>  "bar"
> end
> b = a.clone
> puts B.foo
> puts b.foo
>
> # >> foo
> # >> bar
>
> That is hardly secondary behaviour. We can access an instance's class
> by name (via object.class) - why not the singleton (or extension)
> class?
>
>> I think. I've seen
>> literally hundreds of "Ah ha!" moments where people suddenly grasp the
>> whole per-object thing because once you get the idea of every object
>> having a singleton class, you don't have to learn anything else new
>> (with regard to #extend, etc.).
>
> Well, not hundreds in my case, but it's definitely one of those
> epiphany moments (along with 'classes are objects too'). I think
> naming the elements involved similarly (extend, extension_class,
> extension_methods, etc.) would help clarify the relationship between
> these concepts.

But 'extend' already means something: add a module to the lookup path.
The module that gets added is a completely different object from the
singleton class, and you can extend an object with any number of
modules, anonymous or otherwise. So there's no special identity
between the 'extend' operation and the singleton class. There's a
relation, in the sense that obj.extend(M) is like class << obj;
include M; end, but I don't think there's any reason to name the
singleton class itself in honor of the fact that there's a method
called extend that operates on it, if you see what I mean.


David

-- 
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2)

http://www.wishsight.com => Independent, social wishlist management!