From: dblack@... Date: 2003-07-17T23:08:00+09:00 Subject: Re: reliable way of finding Objects Class? Hello -- On Thu, 17 Jul 2003 walter@mwsewall.com wrote: > Hi, > > is there a reliable way to find the Object's Class. I know about > class and type, but what happens if they are overridden? > > how do you find it then? > > for instance how to find the class at runtime for the following : > > class Obj > def class > "Not My Class" > end > > def type > "don't look here for it" > end > end Note that Object#type is on the way out: $ ruby -ve '1.type' ruby 1.8.0 (2003-06-23) [i686-linux] -e:1: warning: Object#type is deprecated; use Object#class As for finding an object's class without Object#class, I guess you could do something like: >> class Obj; def class; "Go away!"; end; end => nil >> o = Obj.new => # >> a = []; ObjectSpace.each_object(Class) {|c| a << c if o.is_a?(c)} => 346 >> a[-1] => Obj But ObjectSpace.each_object can also be overridden. There's a finite number of ways to get this information, none of which as far as I know is override-proof. David -- David Alan Black home: dblack@superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav