From: Ara.T.Howard@... Date: 2005-05-04T11:45:04+09:00 Subject: Re: un_metaclass On Tue, 3 May 2005 dave.burt@gmail.com wrote: > # This is how to do it: > > class Module > def instances > result = [] > ObjectSpace.each_object do |obj| > result << obj if obj.is_a? self > end > result > end > end it seems to miss much of the time? class Module def instance_class m = %r/^(?:#+)$/io.match inspect if m klass_name, brackets = m[1], m[2] n = brackets.size - 1 klass = const_get klass_name n.times{ klass = class << klass; self; end } klass else superclass end end def instances result = [] ObjectSpace.each_object do |obj| result << obj if obj.is_a? self end result end def both [ instance_class, instances ] end end class C p both class << self p both class << self p both class << self p both end end end end class K < C p both class << self p both class << self p both class << self p both end end end end jib:~/eg/ruby > ruby a.rb [Object, []] [C, [C]] [#, []] [#>, []] [C, []] [K, [K]] [#, []] [#>, []] cheers. -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 ===============================================================================