# Class.descendant\_of?

**URL:** <https://rubytalk.org/t/class-descendant-of/48819>\
**Category:** ruby-talk\
**Created:** [3 September 2008 01:14 UTC](https://rubytalk.org/t/class-descendant-of/48819 "2008-09-03T01:14:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ben\_Johnson1](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@Ben\_Johnson1](https://rubytalk.org/u/Ben_Johnson1)\
**Post date:** [3 September 2008 01:14 UTC](https://rubytalk.org/t/class-descendant-of/48819/1 "2008-09-03T01:14:00Z")

</div>

Noob question:

class A; end  
class B \< A; end

B.kind\_of?(A)

Is there a method that will return true if the class is a descendant of  
that class?

Thanks for your help.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Todd\_Benson](https://avatars.discourse-cdn.com/v4/letter/t/34f0e0/32.png) [@Todd\_Benson](https://rubytalk.org/u/Todd_Benson)\
**Post date:** [3 September 2008 01:31 UTC](https://rubytalk.org/t/class-descendant-of/48819/2 "2008-09-03T01:31:54Z")

</div>

class A; end  
class B \< A; end  
B.ancestors.include?(A)  
=\> true

Todd

> **···**
>
> On Tue, Sep 2, 2008 at 8:14 PM, Ben Johnson \<bjohnson@contuitive.com\> wrote:
> 
> > Noob question:
> > 
> > class A; end  
> > class B \< A; end
> > 
> > B.kind\_of?(A)
> > 
> > Is there a method that will return true if the class is a descendant of  
> > that class?
> > 
> > Thanks for your help.

---

<div class="post-metadata">

**Author:** ![Heesob\_Park](https://avatars.discourse-cdn.com/v4/letter/h/3bc359/32.png) [@Heesob\_Park](https://rubytalk.org/u/Heesob_Park)\
**Post date:** [3 September 2008 01:46 UTC](https://rubytalk.org/t/class-descendant-of/48819/3 "2008-09-03T01:46:03Z")

</div>

class A; end  
class B \< A; end

B \< A  
=\> true

Regards,

Park Heesob

> **···**
>
> 2008/9/3 Ben Johnson \<bjohnson@contuitive.com\>:
> 
> > Noob question:
> > 
> > class A; end  
> > class B \< A; end
> > 
> > B.kind\_of?(A)
> > 
> > Is there a method that will return true if the class is a descendant of  
> > that class?

---

<div class="post-metadata">

**Author:** ![\_Pena\_Botp1](https://avatars.discourse-cdn.com/v4/letter/_/94ad74/32.png) [@\_Pena\_Botp1](https://rubytalk.org/u/_Pena_Botp1)\
**Post date:** [3 September 2008 02:05 UTC](https://rubytalk.org/t/class-descendant-of/48819/4 "2008-09-03T02:05:34Z")

</div>

# Is there a method that will return true if the class is a  
# descendant of that class?

descendant is quite a generic term 😉

compare,

B.ancestors.map {|b| [b, B \< b]}  
#=\> [[B, false], [A, true], [Object, true], [Kernel, true]]

B.ancestors.map {|b| [b, B.superclass == b]}  
#=\> [[B, false], [A, true], [Object, false], [Kernel, false]]

kind regards -botp

> **···**
>
> From: Ben Johnson [[mailto:bjohnson@contuitive.com](mailto:bjohnson@contuitive.com)]
