From: Dorren Date: 2007-06-03T01:45:18+09:00 Subject: Re: so lost on singleton, metaclass and virtual class google group totally screwed up the code, here it is again: -------------------------------------------------------------- # http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html class Object # The hidden singleton lurks behind everyone def metaclass; class << self; self; end; end def show_meta puts "--------- #{to_s} ------------" puts "oid: " + "#{object_id} #{self.class.name}" puts "class.oid: #{self.class.object_id} " + "#{self.class.class.name}" puts "metaclass.oid: #{metaclass.object_id} " + "#{self.class.metaclass.class.name}" o = Object.new # show methods meta = metaclass puts "object methods: " + "#{(public_methods - o.public_methods).sort.inspect}" puts " class methods: " + "#{(self.class.public_methods - o.class.public_methods).sort.inspect}" puts " meta methods: " + "#{(meta.public_methods - Class.public_methods).sort.inspect}" puts end end # ------- fixtures for our test -------------- class A def initialize(v); @v = v; end def to_s; @v; end def m1; "method1 " end def self.class_m0; "class method0"; end end b = A.new("b") c = A.new("c") b.show_meta c.show_meta