Class inheritance tree


(Matthias Veit) #1

Hi,

I miss a convenient way to ask a class, if it is a subclass of
a given superclass (like is_a?, kind_of? for instances).

I wish I could type something like:

Integer.is_superclass?(Fixnum)

Is there a possiblity, I did not know to achieve this?

Best regards,
Matthias

···

Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


(ts) #2

Integer.is_superclass?(Fixnum)

Use the comparison operator

pigeon% ruby -e 'p (Integer > Fixnum)'
true
pigeon%

pigeon% ruby -e 'p (Enumerable > Array)'
true
pigeon%

Guy Decoux


(Vivek Nallur) #3

Hi,

Both superclass as well as ancestors should do the trick

Integer.ancestors would give you
[Integer, Precision, Numeric, Comparable, Object, Kernel]

while

Integer.superclass would give you
Numeric

I guess, you’ll have to do some comparison after this.

regs
Vivek

···

On Tue, 4 Jun 2002, Matthias Veit wrote:

Hi,

I miss a convenient way to ask a class, if it is a subclass of
a given superclass (like is_a?, kind_of? for instances).

I wish I could type something like:

Integer.is_superclass?(Fixnum)

Is there a possiblity, I did not know to achieve this?

Best regards,
Matthias


Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

Grabel’s Law: 2 is not equal to 3 – not even for large values of 2.


(Nobuyoshi Nakada) #4

Hi,

···

At Tue, 4 Jun 2002 20:00:07 +0900, Matthias Veit wrote:

I wish I could type something like:

Integer.is_superclass?(Fixnum)

Integer > Fixnum


Nobu Nakada


(Matthias Veit) #5

… there are reasons to love ruby

Thank you.
Matthias

···

T == ts decoux@moulon.inra.fr wrote:

Integer.is_superclass?(Fixnum)

Use the comparison operator

pigeon% ruby -e 'p (Integer > Fixnum)'
true
pigeon%

pigeon% ruby -e 'p (Enumerable > Array)'
true
pigeon%

Guy Decoux


Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com