[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Finding the super class of an object?

warhero

1/16/2007 3:30:00 AM

How can I find out what the super class is of an object, Say if a class
extends Hash. I need to be able to find a string representation of the
super class ('Hash').... is_a? won't work as that requires an actual
module or class.. I need a string representation.

any ideas? thanks..

--
Posted via http://www.ruby-....

4 Answers

dblack

1/16/2007 3:36:00 AM

0

Justin Collins

1/16/2007 3:50:00 AM

0

Aaron Smith wrote:
> How can I find out what the super class is of an object, Say if a class
> extends Hash. I need to be able to find a string representation of the
> super class ('Hash').... is_a? won't work as that requires an actual
> module or class.. I need a string representation.
>
> any ideas? thanks.

Will Module#ancestors work?

irb(main):001:0> class A
irb(main):002:1> end
=> nil
irb(main):003:0> class B < A
irb(main):004:1> end
=> nil
irb(main):005:0> A.ancestors
=> [A, Object, Kernel]
irb(main):006:0> B.ancestors
=> [B, A, Object, Kernel]


-Justin

bruce

1/16/2007 4:02:00 AM

0

irb(main):013:0> a=10
=> 10
irb(main):014:0> a.class.ancestors
=> [Fixnum, Integer, Precision, Numeric, Comparable, Object, Kernel]
irb(main):015:0> a.class.superclass.name
=> "Integer"
irb(main):016:0>

dblack

1/16/2007 12:44:00 PM

0