From: James Coglan Date: 2008-06-20T07:27:26+09:00 Subject: Re: Why metaclasses? ------=_Part_8805_27172346.1213914528298 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline > 13:32:55 OPSC_Gold_bas_dev_R1.2.2$ irb > Ruby version 1.8.6 > irb(main):001:0> x = Class.new > => # > irb(main):002:0> o = x.new > => #<#:0x7ff9b56c> > irb(main):003:0> o.class > => # > irb(main):004:0> o.class == x > => true > irb(main):005:0> x === o > => true > irb(main):006:0> y = Class.new x > => # > irb(main):007:0> y.superclass > => # > irb(main):008:0> y.superclass == x > => true > irb(main):009:0> u = y.new > => #<#:0x7ff77518> > irb(main):010:0> x === u > => true > irb(main):011:0> y === u > => true > > irb(main):012:0> m = Module.new > => # > irb(main):013:0> y.class_eval { include m } > => # > irb(main):014:0> m === u > => true > irb(main):015:0> y.ancestors > => [#, #, #, > Object, Kernel] > irb(main):016:0> > So x is a class, y is a class that inherits from x (which is to say, y 'includes' x as its first inclusion). o is an x, u is a y (and is therefore an x). Fine. y includes m, so now u is an m as well. y's ancestors are itself, m, x, Object and Kernel. Kernel is the root module, Object is the root class (and therefore includes Kernel). A module's (and therefore a class's) ancestors are itself and its included modules (and *their* included modules, depth first). For a class, this means its included modules, its superclass, its superclass's included modules, and so on. So far I can't see how this is inconsistent with using metamodules instead of metaclasses, and with class inheritance being a special case of module inclusion. With apologies for my apparent slow-wittedness, what am I missing? ------=_Part_8805_27172346.1213914528298--