[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Defining Eigenclass

Matt Todd

8/11/2006 4:37:00 AM

So, what is an eigenclass? I googled it, and couldn't find anything
about it (other than Mauricio's great blog/wiki). Wikipedia doesn't
have anything on it other than an indirect relation to Metaprogramming
(which I already know it's a part of, just not sure wherein).

Can someone provide some information on the idea of an eigenclass?

Thanks,

M.T.

23 Answers

Trans

8/11/2006 4:39:00 AM

0

Google Singleton class. That'll surely help ;-)


Hal E. Fulton

8/11/2006 5:49:00 AM

0

Matt Todd wrote:
> So, what is an eigenclass? I googled it, and couldn't find anything
> about it (other than Mauricio's great blog/wiki). Wikipedia doesn't
> have anything on it other than an indirect relation to Metaprogramming
> (which I already know it's a part of, just not sure wherein).
>
> Can someone provide some information on the idea of an eigenclass?

I'll try. (I call it "singleton class" since that is what I learned.)

It's the "place" where things go that are associated with a specific
*object* rather than a *class* of objects.

For example, if I add a method to an object, that method "lives" in
the singleton class.

superman = "Clark Kent"
def superman.fly
puts "Look! I'm flying!"
end

Here the "fly" method is certainly not part of the String class. No
other string responds to that method -- only this one. It's a
singleton method, and it "lives" in the "singleton class."

You can see more clearly the class-like nature of this thing if
we use this syntax:

class << superman
def fly
#...
end
end

That at least "looks" like a class. But also be aware:
1. It's not a "real" class in that it can't be instantiated.
2. Matz has said that this "thing" *may* not be considered a
class in the future (IIRC).

Note that we can capture the actual value of the singleton class
if we want to:

ssc = class << superman # ssc = superman's singleton class
self # return self as last expression
end

puts ssc.class # Class

Finally, note that what we call "class methods" are just a special
case of singleton methods. Suppose Dog inherits from Mammal; then
suppose we make a Dog.bark class method.

Where does "bark" live? Clearly not "in" Dog (as an instance method
would be "in" it). Not in the parent class, either. It lives in the
singleton class of Dog.

So a "class method" is really just "a singleton method on an object
which happens to be a class."

Does that help any?


Hal

Matt Todd

8/11/2006 12:43:00 PM

0

Yeah, that was very clear. Thanks for the explanation. I just didn't
connect Eigenclasses with Singleton classes.

But, actually, that's a good description of Singleton classes as well.

Thanks!

M.T.

Rick DeNatale

8/11/2006 3:21:00 PM

0

On 8/11/06, Trans <transfire@gmail.com> wrote:
> Google Singleton class. That'll surely help ;-)

The 'official' ruby docs talk about singleton classes, but eigenclass
seems to have been proposed by someone, somewhere, sometime as an
alternative.

This seems to be confined to the ruby community and provides the
subtext for things like eigenclass.org, but I can't seem to find where
the term came from originally.

I'd love enlightenment on that.

Now I guess that the etymology comes from the German word "eigen"
which can be translated to "own" or "individual", and also forms the
root of the mathematical terms "eigenvector" and "eigenvalue". If we
look at "eigenclass" from the perspective of "eigenvector" though, it
doesn't fit that well, since an "eigenvector" of a transformation in
linear algebra is a vector which is unchanged in direction (or more
properly only changes by being multiplied by a scalar) under that
transformation.


--
Rick DeNatale

http://talklikeaduck.denh...

Tom Werner

8/11/2006 4:29:00 PM

0

Rick DeNatale wrote:
>
> The 'official' ruby docs talk about singleton classes, but eigenclass
> seems to have been proposed by someone, somewhere, sometime as an
> alternative.
>

I recalled seeing the discussion in which eigenclass was first proposed.
Here's the post by csaba on April 21, 2005:

<quote>
"Own class" is the best I've heard 'till now in terms of correctness,
it's just a bit "pale". I mean, when you say "I go there by my own
car", then the "own" doesn't refer to a special type of car, it just
refers to some relation of the car with other things. It refers to a
non-intrinsic thing. But if you say
"I go there by my batcar", that makes a difference. Such a thing is
what we need for ruby.
What about "eigenclass", like in eigenvalue?
</quote>

Which was part of the "Article: Seeing Metaclasses Clearly" thread
started by _why on April 17, 2005.
See http://tinyurl....


I much prefer the name "eigenclass" to "singleton class" when referring
to an object's own class. Avoids people having to always qualify what
they mean by singleton class, as you will constantly see people say
things like "when you have a Singleton class (one that include
Singleton, not the eigenclass)", which is just annoying. The term
singleton has already been taken by a design pattern. Besides,
eigenclass is just a neat word. =)

Tom

--
Tom Werner
Helmets to Hardhats
Software Developer
tom@helmetstohardhats.org
www.helmetstohardhats.org

ts

8/11/2006 4:34:00 PM

0

>>>>> "T" == Tom Werner <tom@helmetstohardhats.org> writes:

T> to an object's own class. Avoids people having to always qualify what
T> they mean by singleton class, as you will constantly see people say

Never look at the ruby source, or you'll have a surprise

moulon% grep ^rb_singleton_class ruby-1.8.5/*.c
ruby-1.8.5/class.c:rb_singleton_class_clone(obj)
ruby-1.8.5/class.c:rb_singleton_class_attached(klass, obj)
ruby-1.8.5/class.c:rb_singleton_class(obj)
moulon%


Guy Decoux

Tom Werner

8/11/2006 5:05:00 PM

0

ts wrote:
> Never look at the ruby source, or you'll have a surprise
>
> moulon% grep ^rb_singleton_class ruby-1.8.5/*.c
> ruby-1.8.5/class.c:rb_singleton_class_clone(obj)
> ruby-1.8.5/class.c:rb_singleton_class_attached(klass, obj)
> ruby-1.8.5/class.c:rb_singleton_class(obj)
> moulon%
>
>
> Guy Decoux
>

Indeed the source code tells us what it calls the thing (singleton
class), but should that forbid us from adopting a different, less
ambiguous term when writing about and discussing the concept?

Tom

--
Tom Werner
Helmets to Hardhats
Software Developer
tom@helmetstohardhats.org
www.helmetstohardhats.org


ts

8/11/2006 5:08:00 PM

0

>>>>> "T" == Tom Werner <tom@helmetstohardhats.org> writes:

T> Indeed the source code tells us what it calls the thing (singleton
T> class), but should that forbid us from adopting a different, less
T> ambiguous term when writing about and discussing the concept?

It's ambiguous only for you :-)

What is the next step, eigen method ?


Guy Decoux

Tom Werner

8/11/2006 5:16:00 PM

0

ts wrote:
> T> Indeed the source code tells us what it calls the thing (singleton
> T> class), but should that forbid us from adopting a different, less
> T> ambiguous term when writing about and discussing the concept?
>
> It's ambiguous only for you :-)

If that were true, we wouldn't be having this discussion. =)

Also, see the "nonce" thread going right now for others struggling with
the less-than-stellarness of the currently used "singleton class".

Tom

--
Tom Werner
Helmets to Hardhats
Software Developer
tom@helmetstohardhats.org
www.helmetstohardhats.org


ts

8/11/2006 5:19:00 PM

0

>>>>> "T" == Tom Werner <tom@helmetstohardhats.org> writes:


T> Also, see the "nonce" thread going right now for others struggling with
T> the less-than-stellarness of the currently used "singleton class".

This is the same thread, made by someone which has always had problems
with this term ...

Rien de nouveau sous le soleil ...

Guy Decoux