From: Ara.T.Howard@... Date: 2005-04-30T22:44:27+09:00 Subject: Re: instantiating metaclasses, sorta [Was: determining when inside 'class << self'] On Sat, 30 Apr 2005, Mark Hubbart wrote: > On 4/28/05, Ara.T.Howard wrote: >> >> i like a method like this >> >> def inside_metaclass? >> # to be implemented >> end > > While experimenting with this, I discovered something interesting: it > is possible to instantiate a metaclass. By duping a metaclass, you > regain the ability to instantiate it, apparently without losing any > functionality. > > name = "Jack Smith" > def name.reverse > split.reverse.join ", " > end > name.reverse #==> "Smith, Jack" > > # dup name's metaclass > nameclass = class << name; self; end.dup > > name2 = nameclass.new "John Doe" > name2.reverse #==> "Doe, John" > > Any thoughts? Am I strange for finding this a bit surprising? i dunno - but that's cool. -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | renunciation is not getting rid of the things of this world, but accepting | that they pass away. --aitken roshi ===============================================================================