# How do I tell the difference between a class C and the singleton class of an instance of C

**URL:** <https://www.ruby-forum.com/t/how-do-i-tell-the-difference-between-a-class-c-and-the-singleton-class-of-an-instance-of-c/119075>\
**Category:** Ruby\
**Created:** [November 2, 2007, 9:38pm UTC](https://www.ruby-forum.com/t/how-do-i-tell-the-difference-between-a-class-c-and-the-singleton-class-of-an-instance-of-c/119075 "2007-11-02T21:38:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dean\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bbe5ce/32.png) [@Dean\_W](https://www.ruby-forum.com/u/Dean_W)\
**Post date:** [November 2, 2007, 9:38pm UTC](https://www.ruby-forum.com/t/how-do-i-tell-the-difference-between-a-class-c-and-the-singleton-class-of-an-instance-of-c/119075/1 "2007-11-02T21:38:59Z")

</div>

Suppose that:

class C; end  
c = C.new  
sing = (class \<\< c; self; end)

If a method is called with C and sing, but I don’t know which is first  
and  
which is second in the parameter list, how do I tell them apart?

Thanks,  
dean

---

<div class="post-metadata">

**Author:** ![Dean\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bbe5ce/32.png) [@Dean\_W](https://www.ruby-forum.com/u/Dean_W)\
**Post date:** [November 2, 2007, 9:41pm UTC](https://www.ruby-forum.com/t/how-do-i-tell-the-difference-between-a-class-c-and-the-singleton-class-of-an-instance-of-c/119075/2 "2007-11-02T21:41:54Z")

</div>

I just figured out a way, if I also have the instance “c”.

c.instance\_of?© # =\> true  
c.instance\_of?(sing) # =\> false

Also works for kind\_of? and is\_a?

Thanks, Dean! 😉

---

<div class="post-metadata">

**Author:** ![Dean\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bbe5ce/32.png) [@Dean\_W](https://www.ruby-forum.com/u/Dean_W)\
**Post date:** [November 2, 2007, 9:44pm UTC](https://www.ruby-forum.com/t/how-do-i-tell-the-difference-between-a-class-c-and-the-singleton-class-of-an-instance-of-c/119075/3 "2007-11-02T21:44:50Z")

</div>

“Dean W.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> Suppose that:
> 
> class C; end  
> c = C.new  
> sing = (class \<\< c; self; end)
> 
> If a method is called with C and sing, but I don’t know which is first and  
> which is second in the parameter list, how do I tell them apart?

C.name ==\> “C”  
sing.name ==\> “”

YS

---

<div class="post-metadata">

**Author:** ![Dean\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bbe5ce/32.png) [@Dean\_W](https://www.ruby-forum.com/u/Dean_W)\
**Post date:** [November 2, 2007, 9:53pm UTC](https://www.ruby-forum.com/t/how-do-i-tell-the-difference-between-a-class-c-and-the-singleton-class-of-an-instance-of-c/119075/4 "2007-11-02T21:53:36Z")

</div>

Thanks.

Correction: only instance\_of? works. is\_a? and kind\_a? both return true  
for  
“C” and “sing”.
