Hi --

On Mon, 8 Mar 2004, Simon Strandgaard wrote:

> I wasn't sure about what kind of reopening you talked about in last mail.
> Yes, I have used this a few times. However I am only interested in
> modifying a specific instance with 'class<<obj'.

Here's another way to look at all of this.  

You're right that extending an object is in the same family of
operations, so to speak, as defining methods in that object's
singleton class.  However, within that family (things that affect what
messages the object responds to, and/or how it responds to them),
those two things are in a sense the opposite of each other.  

The methods added to an object's capabilities by obj.extend(Mod) are,
typically, methods which also get added to other objects (since that
what modules are good at).  Therefore, extending an object tends to
move it in the direction of having more in common with other objects
-- for example, enumerability.

Defining a method in an object's singleton class, however, whether one
does it like this:

  def obj.meth ...

or like this:

  class << obj
    def meth ...

is the opposite: it represents a decision to increase the difference
between obj and other objects.

So, in addition to the consistency Matz was talking about (keeping all
class reopenings the same), I think there's also this difference in
role or intention that actually makes singleton methods rather
un-extend-like.  


David

-- 
David A. Black
dblack / wobblini.net