Now that's interesting...

When I ask, "Why *can't* we subclass Class?" it's because I *can't*... but
you did!  For me, when it gives:

  can't make subclass of Class (TypeError)

This is ruby 1.7.3 (2002-11-17) [i386-mswin32].

What I was trying to do was make a new Class, called NewClass, which would
work like this:

  NewClass = Class.new Class

  A = Class.new     #  Creates a class.
  B = NewClass.new  #  Creates a class (I was hoping).

  A.kind_of? Class  #  -->  true
  B.kind_of? Class  #  -->  true

  a = A.new
  b = B.new

Seems to me that any object which defines a 'new' method should be
considered a class... isn't this one of the major ideas behind dynamic
typing?

I understand that if you use the following language construct:

  class Foo
  end

...this is the same as 'Foo = Class.new', and that there is no corresponding
language construct for creating classes of any other klass (their klass
pointers currently ALWAYS point to Class), but why isn't it allowed?


----- Original Message -----
Just an example (it's 1.7)

pigeon% cat b.rb
#!./ruby
class A < Class
   def self.a
      p "a"
   end

   def a
      p "a"
   end
end

b = A.new
b.a
pigeon%

pigeon% b.rb
/b.rb:13: undefined method `a' for #<Class:0x401ac244> (NoMethodError)
pigeon%

----------------------------

This makes perfect sense.  A is a class-making class (like Class is).  It
inherits Class's new method, which creates a new instance of Class, not of
A.  *This* is what I was trying to show (but I can't subclass classes, so
thank you!).

This just tells me that Class.new is broken.  It should return an object
whose klass pointer is *self*, not Class.  Then the above code would work,
and we could get rid of singleton classes altogether, in favor of simply
inserting real classes into the hierarchy.  This would also encourage people
to use #kind_of? instead of #class, which is a Good Thing.

We would still have all of the functionality singleton classes now provide,
but no 'special hidden singleton' classes, which even matz says are not part
of the Ruby language (only this implementation of it).

Ruby 2.0 anyone?  :)

Seriously, I'm no language designer, so if there are other problems with
subclassing Class (in principle, not in the current implementation), please
tell me what they are.

Chris