Hi -- On Fri, 13 Dec 2002, Chris Pine wrote: > 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: Guy has his own versions of Ruby, and doesn't always explicitly tell us he's using them. (Guy, do you have a "-w" flag? :-) It's an easy hack, though, if you want to try it. In 1.7, look in class.c for rb_class_new, and comment out the tests. (I think it was in object.c earlier.) > ----- 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. They're both forms of testing for type, which I'm not a big fan of personally. I'd rather see the role of class hierarchies diminish than see it grow, and more be made of the behavior of objects at a given point in their lifespan. > 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). If I understand matz's remarks correctly, this question of implementation is not a question of semantics. In other words, the "singleton class notation" (class << obj) is a semantic feature of Ruby. How it's implemented (whether through the creation of a class object, or otherwise) is another matter. Although... I'm actually not sure how different an implementation could be, since presumably "class << obj; self; end" has to evaluate to something. I guess that's actually part of what matz considers abusive use of that notation (http://www.ruby-talk.org/40548). In any case, if there's a way to do singleton methods without singleton classes, I guess that would be OK (though I actually cannot picture how it would work). But I don't think we'd then want to see the ghosts of singleton classes becoming real classes. David -- David Alan Black home: dblack / candle.superlink.net work: blackdav / shu.edu Web: http://pirate.shu.edu/~blackdav