Any official name for Ruby's class which makes "class methods"?

We all know Ruby really doesn't have class methods.

But how do you call such classes that have "class methods"?
I hear Japanese say 特異 class, but is there any English word for that?

Is eigenclass an official name for that?

Trying to figure it out by looking into documentation, but I haven't found
any official call.

- J

Hunt Jon wrote:

We all know Ruby really doesn't have class methods.

But how do you call such classes that have "class methods"?
I hear Japanese say 特異 class, but is there any English word for that?

You mean instances of class Class? The official docs call them
metaclasses.

Is eigenclass an official name for that?

I think -- and I could be confused -- that "eigenclass" is a synonym for
"singleton class". I never use the word myself, so I'm not certain.

Trying to figure it out by looking into documentation, but I haven't
found
any official call.

- J

Best,

···

--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
--
Posted via http://www.ruby-forum.com/\.

We all know Ruby really doesn't have class methods.

But how do you call such classes that have "class methods"?

This question is different from your subject.

A class that has class methods is just called a class. So I shall assume that the word "make" in the subject is the actual key to your question...

Assuming I interpret the question correctly, the question itself is flawed. Since ruby isn't metacircularly defined, there isn't a class that makes/creates class methods (or singleton methods on a class instance... I shall call them class methods). Either the parser creates them when it loads and evals a file, or the methods are dynamically created at runtime via one of many methods.

If you're instead asking "what's the name of the final destination of a class method?" then ... yeah. prolly eigenclass or metaclass. I prefer to think of them simply as "class methods" and not worry about it.

Trying to figure it out by looking into documentation, but I haven't found
any official call.

yeah. I think that is partially because the slightly mislabeled "class method" is good enough for most of us and we simply haven't needed a more accurate term for 99% of our discussions.

···

On Nov 15, 2009, at 18:45 , Hunt Jon wrote:

Hi --

Hunt Jon wrote:

We all know Ruby really doesn't have class methods.

But how do you call such classes that have "class methods"?
I hear Japanese say 特異 class, but is there any English word for that?

You mean instances of class Class? The official docs call them
metaclasses.

I don't think that's right. String and Array and

   class MyClass

and Class.new are all instances of Class, but they're not metaclasses.

Actually, I think it was Jim Weirich who pointed out that, given the
usual sense of the term "metaclass" as a class which produces other
classes, Class itself is the only metaclass in Ruby. The term is
sometimes used to refer to singleton classes in general, and sometimes
to refer only to singleton classes of Class objects:

   s = ""
   class << s; self; end # s's singleton class
   class << String; self; end # String's singleton class or metaclass

This usage (using it for classes' singleton classes) has some
justification because classes' s. classes aren't quite the same as
those of other objects (they allow for method-sharing by subclasses,
so they're not strictly "per-object" definitions). I myself usually
stick to "singleton class" all around, partly just to do my bit to
stop the name-proliferation madness :slight_smile: I don't see anything "meta"
about singleton classes in general, so I don't call them metaclasses.

Is eigenclass an official name for that?

No (at least, I hope not :slight_smile: Matz had expressed uncertainty about the
naming scheme, and a bunch of more or less whimsical names were
suggested, some of which seem to have a certain following. The
unfortunate effect is that it's all a bit unclear.

I recommend "singleton class", plus "metaclass" for classes' singleton
classes if you feel strongly about their special status. I'll add that
in nine years of using Ruby, I have yet to see more than perhaps one
or two cases of confusion between singleton classes and
classes that include the Singleton module (totalling about four
seconds and cleared up with: "No, that's different"), though that
coincidence of names is often adduced as evidence that "singleton
class" must be a confusing name.

David

···

On Mon, 16 Nov 2009, Marnen Laibow-Koser wrote:

--
THE COMPLEAT RUBYIST, Ruby training with Black/Brown/McAnally!
January 22-23, Tampa, Florica
Info and registration at http://www.thecompleatrubyist.com
--------------------------------------
My new job: http://tinyurl.com/yfpn9hz

David A. Black wrote:

Hi --

Hunt Jon wrote:

We all know Ruby really doesn't have class methods.

But how do you call such classes that have "class methods"?
I hear Japanese say 特異 class, but is there any English word for that?

You mean instances of class Class? The official docs call them
metaclasses.

I don't think that's right. String and Array and

   class MyClass

and Class.new are all instances of Class, but they're not metaclasses.

I thought it was strange too, but take a look:

Actually, I think it was Jim Weirich who pointed out that, given the
usual sense of the term "metaclass" as a class which produces other
classes, Class itself is the only metaclass in Ruby.

I think he's right, but that's not the sense in which the official docs
use the term.

[...]

David

Best,

···

On Mon, 16 Nov 2009, Marnen Laibow-Koser wrote:

--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
--
Posted via http://www.ruby-forum.com/\.

I usually don't disagree with my younger friend Jim, but...

In general, although in some languages the implementation of
metaclasses is involved with creating other classes, the more general
meaning is that a metaclass is a class whose instance(s) are classes.
Granted Ruby is a bit sneaky in this regard since the class METHOD
sometimes hides the klass linkage, but if you look at ruby
documentation such as
Class: Class (Ruby 1.8.7) you'll see that
it talks about multiple metaclasses, and although it point's out that
the vertical lines in the diagram represent inheritance, it leaves the
description of the horizontal lines, which link Object to (Object),
OtherClass to (OtherClass) etc. These are of course the klass
pointers, and despite the smoke thrown by the class method which skips
over 'virtual/singleton' classes,

It might be of interest to note that early Smalltalk versions had only
one metaclass and it was Class, but this was limiting because it meant
that all classes had to have the same message protocol, since the
metaclass is where the method dictionary used to find methods for a
class lives, much as the String class is where the method dictionary
used to find methods for instances of strings is stored (of course I'm
simplifying a bit here, these are really where the first method
dictionary consulted is found before looking for inherited methods).

So, in Smalltalk at least, the first step in making Metaclasses more
'First class' was to allow each class to have its own metaclass,

And in Smalltalk metaclasses don't create other classes, much as in
Ruby, when a class is created, by sending it the subclass:... method,
a metaclass for the new class is created automatically, so it's the
other way around really.

The real role of a metaclass is to serve as the class of its sole
class instance, much like (singleton) classes serve as the class of
their instance or instances.

Now Smalltalk-80 makes Metaclasses more apparent, and factors things
by Having a class Hierarchy like this

Object
    Behavior - provides the minimal state necessary for objects that
have instances.
                   It is really the interface with the VM. For
Smalltalk this is where the
                   instance variables for the method dictionary, the
superclass link,
                   and the form of instances (Smalltalk instances can
contain either
                   a sequence of either object pointers, bits, bytes or words,
                   and this sequence may be fixed or variable in length.
    ClassDescription - this is the interface to the IDE and the compiler,
                   it provides instance variables for naming the 'Class',
                   naming the instance variables, and for a comment
shown in the browser
        Class - adds support for things like class variable names,
                   and shared pool dictionaries which provide for something
                   like Module scoped names in Ruby
       Metaclass - primarily this adds the behavior needed to create a new
                   Metaclass, initialize it and link it into the
parallel inheritance hierarchy.

Now Ruby doesn't have an equivalent for ClassDescription, and might
not have a class named Metaclass, but if you account for that, the
inheritance/instance-of diagram in the official document of Class
looks very much like the same diagram for Smalltalk with the
appropriate removals.

The real difference is that Ruby makes an attempt to hide the "Man
behind the curtains." and Smalltalk makes the "wizard" visible, and
refactors him into multiple bits.

···

On Tue, Nov 17, 2009 at 6:30 AM, David A. Black <dblack@rubypal.com> wrote:

Actually, I think it was Jim Weirich who pointed out that, given the
usual sense of the term "metaclass" as a class which produces other
classes, Class itself is the only metaclass in Ruby. The term is
sometimes used to refer to singleton classes in general, and sometimes
to refer only to singleton classes of Class objects:

--
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

It says:

   All metaclasses are instances of the class `Class'.

but it does not say that all instances of Class are metaclasses :slight_smile:
That would make "metaclass" a synonym for "class", which wouldn't make
sense.

David

···

On Tue, 17 Nov 2009, Marnen Laibow-Koser wrote:

David A. Black wrote:

Hi --

On Mon, 16 Nov 2009, Marnen Laibow-Koser wrote:

Hunt Jon wrote:

We all know Ruby really doesn't have class methods.

But how do you call such classes that have "class methods"?
I hear Japanese say 特異 class, but is there any English word for that?

You mean instances of class Class? The official docs call them
metaclasses.

I don't think that's right. String and Array and

   class MyClass

and Class.new are all instances of Class, but they're not metaclasses.

I thought it was strange too, but take a look:
Class: Class (Ruby 1.8.7)

--
THE COMPLEAT RUBYIST, Ruby training with Black/Brown/McAnally!
January 22-23, Tampa, Florida
Info and registration at http://www.thecompleatrubyist.com
--------------------------------------
My new job: http://tinyurl.com/yfpn9hz

Let's detach it from Jim unless he chimes in himself. I mentioned him
because I thought I remembered hearing this characterization from him,
but if there are inaccuracies in what I'm saying I don't want history
to record them as having come from Jim.

David

···

On Wed, 18 Nov 2009, Rick DeNatale wrote:

On Tue, Nov 17, 2009 at 6:30 AM, David A. Black <dblack@rubypal.com> wrote:

Actually, I think it was Jim Weirich who pointed out that, given the
usual sense of the term "metaclass" as a class which produces other
classes, Class itself is the only metaclass in Ruby. The term is
sometimes used to refer to singleton classes in general, and sometimes
to refer only to singleton classes of Class objects:

I usually don't disagree with my younger friend Jim, but...

--
THE COMPLEAT RUBYIST, Ruby training with Black/Brown/McAnally!
January 22-23, Tampa, Florida
Info and registration at http://www.thecompleatrubyist.com
--------------------------------------
My new job: http://tinyurl.com/yfpn9hz

Rick DeNatale wrote:

Actually, I think it was Jim Weirich who pointed out that, given the
usual sense of the term "metaclass" as a class which produces other
classes, Class itself is the only metaclass in Ruby. The term is
sometimes used to refer to singleton classes in general, and sometimes
to refer only to singleton classes of Class objects:
    

And I dislike this usage. The whole problem seems to stem from a general confusion of the meaning of the term meta programming (where eigen/singleton/virtual classes ofen play a role in Ruby) with the fact, that Matz couldn't yet decide how to call these thingies. But some day, eventually...

I usually don't disagree with my younger friend Jim, but...

In general, although in some languages the implementation of
metaclasses is involved with creating other classes, the more general
meaning is that a metaclass is a class whose instance(s) are classes.
  

Do you have found any other examples of these classes whose instances are classes besides Class? I haven't. If you try to create instances like this

>> MyClass = Class.new(Class)
# => MyClass
>> Foo = MyClass.new do def foo() end end
TypeError: wrong instance allocation
    from (irb):2:in `new'
    from (irb):2

or even this

>> MyClass = Class.dup
# => MyClass
>> Foo = MyClass.new do def foo() end end
TypeError: wrong instance allocation
    from (irb):4:in `new'
    from (irb):4

Ruby does a hard type check and throws an exception. This is where you have broken through Ruby's thin layer of abstraction around its C-internals, while Smalltalk is much more turtles all the way down.

This is different from Module, BTW:

>> MyModule = Class.new(Module)
# => MyModule
>> Foo = MyModule.new do def bar() end end
# => Foo
>> class A; include Foo ; end
# => A
>> A.new.bar
# => nil

So you could say, Ruby has one metaclass, but can have lots of metamodules.

···

--
Florian Frank

David A. Black wrote:

Class: Class (Ruby 1.8.7)

It says:

   All metaclasses are instances of the class `Class'.

but it does not say that all instances of Class are metaclasses :slight_smile:

But I think that is what is meant. How else does the diagram on that
page make sense? Every class has an associated metaclass of the same
name in that diagram. What is that if not the Class object?

That would make "metaclass" a synonym for "class", which wouldn't make
sense.

I think that "metaclass" is here a synonym for the Class object, as
opposed to the class declaratio or anything else.

David

Best,

···

On Tue, 17 Nov 2009, Marnen Laibow-Koser wrote:

--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
--
Posted via http://www.ruby-forum.com/\.

Actually no I didn't. I believe that it was David A. Black.

I've been standing off from this thread. I'm writing a blog article,
which I've been meaning to for at least a year, called "The object
which must not be named" I hope to publish it soon.

···

On Thu, Nov 19, 2009 at 11:46 AM, Florian Frank <flori@ping.de> wrote:

Rick DeNatale wrote:

Actually, I think it was Jim Weirich who pointed out that, given the
usual sense of the term "metaclass" as a class which produces other
classes, Class itself is the only metaclass in Ruby. The term is
sometimes used to refer to singleton classes in general, and sometimes
to refer only to singleton classes of Class objects:

--
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

Then how does the sentence before the sentence you originally quoted make sense:

In the diagram that follows, the vertical arrows represent
inheritance, and the parentheses meta-classes. All metaclasses are
instances of the class `Class’.

There are lots of parenthesized 'metaclasses' and none ARE Class.

···

On Tue, Nov 17, 2009 at 10:12 AM, Marnen Laibow-Koser <marnen@marnen.org> wrote:

David A. Black wrote:

On Tue, 17 Nov 2009, Marnen Laibow-Koser wrote:

Class: Class (Ruby 1.8.7)

It says:

All metaclasses are instances of the class `Class'.

but it does not say that all instances of Class are metaclasses :slight_smile:

But I think that is what is meant. How else does the diagram on that
page make sense? Every class has an associated metaclass of the same
name in that diagram. What is that if not the Class object?

That would make "metaclass" a synonym for "class", which wouldn't make
sense.

I think that "metaclass" is here a synonym for the Class object, as
opposed to the class declaratio or anything else.

--
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

Hi --

David A. Black wrote:

Class: Class (Ruby 1.8.7)

It says:

   All metaclasses are instances of the class `Class'.

but it does not say that all instances of Class are metaclasses :slight_smile:

But I think that is what is meant. How else does the diagram on that
page make sense? Every class has an associated metaclass of the same
name in that diagram. What is that if not the Class object?

The metaclasses are anonymous. The metaclass (or whatever we call it)
of String, for example, is a completely separate class/object from
String:

String.object_id

=> 1143790

class << String; object_id; end

=> 1143780

That would make "metaclass" a synonym for "class", which wouldn't make
sense.

I think that "metaclass" is here a synonym for the Class object, as
opposed to the class declaratio or anything else.

Class is itself an object (and a class). But it is definitely not the
metaclass/singleton class of any other object:

class << String; object_id; end

=> 1143780

Class.object_id

=> 1148540

David

···

On Wed, 18 Nov 2009, Marnen Laibow-Koser wrote:

On Tue, 17 Nov 2009, Marnen Laibow-Koser wrote:

--
THE COMPLEAT RUBYIST, Ruby training with Black/Brown/McAnally!
January 22-23, Tampa, Florida
Info and registration at http://www.thecompleatrubyist.com
--------------------------------------
My new job: http://tinyurl.com/yfpn9hz

I wonder if there's still no metaclass accessor in 1.9 to avoid
picking a name :D.

Rick Denatale wrote:

But I think that is what is meant. �How else does the diagram on that
page make sense? �Every class has an associated metaclass of the same
name in that diagram. �What is that if not the Class object?

That would make "metaclass" a synonym for "class", which wouldn't make
sense.

I think that "metaclass" is here a synonym for the Class object, as
opposed to the class declaratio or anything else.

Then how does the sentence before the sentence you originally quoted
make sense:

In the diagram that follows, the vertical arrows represent
inheritance, and the parentheses meta-classes. All metaclasses are
instances of the class `Class�.

There are lots of parenthesized 'metaclasses' and none ARE Class.

I took the parenthesized items on the diagram to be the actual Class
objects, while the nonparenthesized items were the classes that most
programmers are more likely to interact with.

It's strange, I know, but I really can't think of an interpretation that
makes more sense.

--
Rick DeNatale

Best,

···

On Tue, Nov 17, 2009 at 10:12 AM, Marnen Laibow-Koser > <marnen@marnen.org> wrote:

--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
--
Posted via http://www.ruby-forum.com/\.

David A. Black wrote:
> The metaclasses are anonymous. The metaclass (or whatever we call it)
> of String, for example, is a completely separate class/object from
> String:

Yes. And these things, that shall never be named, aren't much like
classes either: They cannot create any instances for example. In Ruby
terminology they are much closer to modules in the sense, that they are
containers of methods, that are used to extend objects.

···

--
Florian Frank

David A. Black wrote:

The metaclasses are anonymous. The metaclass (or whatever we call it)
of String, for example, is a completely separate class/object from
String:

Yes. And these things, that shall never be named, aren't much like classes either: They cannot create any instances for example. In Ruby terminology they are much closer to modules in the sense, that they are containers of methods, that are used to extend objects.

Hi --

Rick Denatale wrote:

But I think that is what is meant. ???How else does the diagram on that
page make sense? ???Every class has an associated metaclass of the same
name in that diagram. ???What is that if not the Class object?

That would make "metaclass" a synonym for "class", which wouldn't make
sense.

I think that "metaclass" is here a synonym for the Class object, as
opposed to the class declaratio or anything else.

Then how does the sentence before the sentence you originally quoted
make sense:

In the diagram that follows, the vertical arrows represent
inheritance, and the parentheses meta-classes. All metaclasses are
instances of the class `Class???.

There are lots of parenthesized 'metaclasses' and none ARE Class.

I took the parenthesized items on the diagram to be the actual Class
objects, while the nonparenthesized items were the classes that most
programmers are more likely to interact with.

It's strange, I know, but I really can't think of an interpretation that
makes more sense.

They're all instances of Class, and thus all actual Class objects.

Every Ruby object has what I sometimes call a "birth" class (String
for "abc", Class for Object, etc.), and then in addition, every object
(almost) may, optionally, have a singleton class. The singleton class,
which is anonymous, exists for the purpose of serving as the
repository of singleton methods for this object, and to provide a node
on the method lookup path where modules can be included for this
object only.

It's kind of a nature/nurture thing. The original nature of the object
is represented by its "birth" class. The nurture of the object -- the
processes by which it branches away from what would otherwise have
been the entirety of its identity -- is carried out via its singleton
class. (Of course, this analogy doesn't take into account the fact
that the "birth" class can change dynamically. But it's a good start.)

Matz has always emphasized that the main thing here is the
individuation and dynamism of objects, and that the two-class model is
just a way to implement that dynamism. He's even discussed in the past
the possibility of doing it some other way in the future, though my
recent understanding is that the two-class way is probably here to
stay, at least for the foreseeable future. And it works really well,
partly because you get the same interface to the singleton class that
you do to the "birth" class (the class keyword).

David

···

On Wed, 18 Nov 2009, Marnen Laibow-Koser wrote:

On Tue, Nov 17, 2009 at 10:12 AM, Marnen Laibow-Koser >> <marnen@marnen.org> wrote:

--
THE COMPLEAT RUBYIST, Ruby training with Black/Brown/McAnally!
January 22-23, Tampa, Florida
Info and registration at http://www.thecompleatrubyist.com
--------------------------------------
My new job: http://tinyurl.com/yfpn9hz

Hi --

···

On Fri, 20 Nov 2009, Florian Frank wrote:

David A. Black wrote:

The metaclasses are anonymous. The metaclass (or whatever we call it)
of String, for example, is a completely separate class/object from
String:

Yes. And these things, that shall never be named, aren't much like
classes either: They cannot create any instances for example. In Ruby
terminology they are much closer to modules in the sense, that they are
containers of methods, that are used to extend objects.

I could definitely imagine 'singleton module' instead of 'singleton
class'. I think Matz has commented on this choice but I can't remember
any details.

David

--
THE COMPLEAT RUBYIST, Ruby training with Black/Brown/McAnally!
January 22-23, Tampa, Florida
Info and registration at http://www.thecompleatrubyist.com
--------------------------------------
My new job: http://tinyurl.com/yfpn9hz

I was thinking along the same lines while reading this thread. There are a few characteristics that seem to argue for class implementation vs a module implementation:

-- the class/instance relationship doesn't have an analog
    with modules and an object can be viewed as an "instance"
    of its singleton class

-- the inheritance relationship of classes provides a
    structure for searching singleton classes of classes that
    also no analog with modules

These aren't strong reasons for a class implementation over a module implementation but it seems like a module implementation would involve adding special case semantics to the 'singleton modules' that aren't as 'special' in the current singleton class implementation.

Gary Wright

···

On Nov 19, 2009, at 5:50 PM, David A. Black wrote:

On Fri, 20 Nov 2009, Florian Frank wrote:

David A. Black wrote:

The metaclasses are anonymous. The metaclass (or whatever we call it)
of String, for example, is a completely separate class/object from
String:

Yes. And these things, that shall never be named, aren't much like
classes either: They cannot create any instances for example. In Ruby
terminology they are much closer to modules in the sense, that they are
containers of methods, that are used to extend objects.

I could definitely imagine 'singleton module' instead of 'singleton
class'. I think Matz has commented on this choice but I can't remember
any details.