From: Quintus Date: 2010-08-06T18:25:27+09:00 Subject: Re: lt operator on class object, checking a class' superclasses -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Am 06.08.2010 10:57, schrieb Tomasz Wrobel: > Hi! > > Do you know a good way to check whether a class is a subclass of a > certain class (given the class object, not an instance)? > > one way would be to check all of klass.superclass, > klass.superclass.superclass till nil > > or klass.new.is_a?( cklass ) > > Accidentaly, I tried to such a operation: > > klass < cklass > > and it seems to work, but doesn't seem to be documented > can somebody acknowledge this? > > Best regards, > Tomek W It is documented, although it may be a bit hard to find, since the behaviour is not defined in the Class class as one might expect, but in it's superclass, Module. See the Module#<, Module#>, Module#<= and Module#>= methods on http://www.ruby-doc.org/ruby-1.9/index.html . I'm not sure what about Module#<=> since the docs say it works on mixins, but it appears to work on classes as well. Vale, Marvin -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkxb1O0ACgkQDYShvwAbcNkNmACgjN0UrOwkN3iuhovolkoXjWgM OWYAoIOPgogYxBm2QHGkFSvmpO181yAe =/E5l -----END PGP SIGNATURE-----