From: Florian Frank Date: 2009-11-20T01:46:50+09:00 Subject: Re: Any official name for Ruby's class which makes "class me 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