From: Daniel Brockman Date: 2005-07-15T11:29:12+09:00 Subject: Re: difference? "Gene Tani" writes: > Hmm, seems to be few ways to test/monitor > membership/inheritance/mix-in-ness: Indeed. :-) > Object#kind_of?, #is_a?, > > Module#ancestors, > > MyClassname === myobj Interestingly, you've listed these in order of preference: * foo.kind_of? Foo --- perfect * foo.is_a? Foo --- unrubyish due to `is_*?' * foo.class.ancestors.include? Foo --- long-winded and confusing * Foo === foo --- confusing and unnecessary Of course, when checking multiple cases, this is perfect: case foo when Foo ... when Bar ... when Baz ... end However, > #instance_of?, #type (deprecated), #class I'd order the ways of checking the exact class like this: * foo.class == Foo --- perfect * foo.instance_of? Foo --- obscures the semantics * foo.type == Foo --- deprecated > Module#included_modules, Class#inherited (I left these out because they are normally useless, and primarily serve as hooks to make obscure object-system hackery possible.) In the same vein, there's alse Class#superclass. -- Daniel Brockman