From: Gene Tani Date: 2005-10-03T22:26:47+09:00 Subject: Re: Cannot subclass Class? Alex martelli's talk on python metaclasses, if you're curious, they're really not too complicated: http://www.python.org/pycon/2005/papers/36/pyc05_bla_dp.pdf Good reminder about meta-slippage. I've been trying to wrap my brain around all the meta's in Jim Weirich's picture: http://onestepback.org/images/rubyobjects.png David A. Black wrote: > Hi -- > > On Mon, 3 Oct 2005, Rob Rypka wrote: > > > On 10/2/05, itsme213 wrote: > >> irb(main):006:0> class MC < Class > >> irb(main):007:1> end > >> TypeError: can't make subclass of Class > >> > >> Why is this? Is it a language restriction or a 1.8.2 limitation? > >> > >> Are there other ways to define new meta-classes? > > > > I was trying to figure out exactly what metaclasses allow you to do, > > and I came across the following quote: > > > > Metaclasses are deeper magic than 99% of users should ever worry > > about. If you wonder whether you need them, you don't (the people who > > actually need them know with certainty that they need them, and don't > > need an explanation about why). > > -- Python Guru Tim Peters > > > > If you've got an example of something you want to do with metaclasses > > in Ruby, post it here. I'll bet you get a lot of suggestions that are > > less "brain-melting," as the Python folks like to say. > > I don't know what the term refers to in Python, but I do know that in > Ruby there's been a lot of terminological slippage over the years. > Some people use "metaclass" to refer to all singleton classes. Others > use it to refer to the singleton classes of class objects. Other have > argued that the only real metaclass in Ruby is the class Class (if you > define a metaclass as a class that produces classes). > > Singleton classes in general are definitely not deep magic. They're > just the way Ruby handles requests for per-object method definitions: > stick them in a per-object class. They're not particularly meta; > they're just anonymous classes. > > Singleton classes of class objects are probably the most frequently > made use of, since that's where class methods live. I think you see > this: > > class C > class << self > > more often than class << obj where obj is not a class. > > And class Class is just class Class :-) > > So the question of what "metaclasses" allow you to do depends a bit on > what you mean exactly, but I don't think there's much mystery or > reason for people not to try to understand them. > > > David > > -- > David A. Black > dblack@wobblini.net