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

**URL:** <https://rubytalk.org/t/how-do-i-tell-the-difference-between-a-class-c-and-the-singleton-class-of-an-instance-of-c/41876>\
**Category:** ruby-talk\
**Created:** [2 November 2007 20:36 UTC](https://rubytalk.org/t/how-do-i-tell-the-difference-between-a-class-c-and-the-singleton-class-of-an-instance-of-c/41876 "2007-11-02T20:36:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dean\_Wampler](https://avatars.discourse-cdn.com/v4/letter/d/cc9497/32.png) [@Dean\_Wampler](https://rubytalk.org/u/Dean_Wampler)\
**Post date:** [2 November 2007 20:36 UTC](https://rubytalk.org/t/how-do-i-tell-the-difference-between-a-class-c-and-the-singleton-class-of-an-instance-of-c/41876/1 "2007-11-02T20:36:05Z")

</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

> **···**
>
> --  
> Dean Wampler  
> [http://www.objectmentor.com](http://www.objectmentor.com)  
> [http://www.aspectprogramming.com](http://www.aspectprogramming.com)  
> [http://aquarium.rubyforge.org](http://aquarium.rubyforge.org)
> 
> > **[Hand Feeding Hummingbirds | Best Hand Feeders | Contract4j](http://www.contract4j.org)**
> >
> > Learn how to hand feed hummingbirds. Best hummingbird hand held feeders for usage this upcoming hummingbird season.

---

<div class="post-metadata">

**Author:** ![Dean\_Wampler](https://avatars.discourse-cdn.com/v4/letter/d/cc9497/32.png) [@Dean\_Wampler](https://rubytalk.org/u/Dean_Wampler)\
**Post date:** [2 November 2007 20:41 UTC](https://rubytalk.org/t/how-do-i-tell-the-difference-between-a-class-c-and-the-singleton-class-of-an-instance-of-c/41876/2 "2007-11-02T20:41:25Z")

</div>

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

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

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

Thanks, Dean! 😉

> **···**
>
> On 11/2/07, Dean Wampler \<deanwampler@gmail.com\> wrote:
> 
> > 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
> > 
> > --  
> > Dean Wampler  
> > [http://www.objectmentor.com](http://www.objectmentor.com)  
> > [http://www.aspectprogramming.com](http://www.aspectprogramming.com)  
> > [http://aquarium.rubyforge.org](http://aquarium.rubyforge.org)  
> > [http://www.contract4j.org](http://www.contract4j.org)
> 
> --  
> Dean Wampler  
> [http://www.objectmentor.com](http://www.objectmentor.com)  
> [http://www.aspectprogramming.com](http://www.aspectprogramming.com)  
> [http://aquarium.rubyforge.org](http://aquarium.rubyforge.org)  
> [http://www.contract4j.org](http://www.contract4j.org)

---

<div class="post-metadata">

**Author:** ![Yohanes\_Santoso1](https://avatars.discourse-cdn.com/v4/letter/y/ccd318/32.png) [@Yohanes\_Santoso1](https://rubytalk.org/u/Yohanes_Santoso1)\
**Post date:** [2 November 2007 20:44 UTC](https://rubytalk.org/t/how-do-i-tell-the-difference-between-a-class-c-and-the-singleton-class-of-an-instance-of-c/41876/3 "2007-11-02T20:44:06Z")

</div>

"Dean Wampler" \<deanwampler@gmail.com\> 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\_Wampler](https://avatars.discourse-cdn.com/v4/letter/d/cc9497/32.png) [@Dean\_Wampler](https://rubytalk.org/u/Dean_Wampler)\
**Post date:** [2 November 2007 20:52 UTC](https://rubytalk.org/t/how-do-i-tell-the-difference-between-a-class-c-and-the-singleton-class-of-an-instance-of-c/41876/4 "2007-11-02T20:52:48Z")

</div>

Thanks.

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

> **···**
>
> On 11/2/07, Yohanes Santoso \<ysantoso-rubytalk@dessyku.is-a-geek.org\> wrote:
> 
> > "Dean Wampler" \<deanwampler@gmail.com\> 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
> 
> --  
> Dean Wampler  
> [http://www.objectmentor.com](http://www.objectmentor.com)  
> [http://www.aspectprogramming.com](http://www.aspectprogramming.com)  
> [http://aquarium.rubyforge.org](http://aquarium.rubyforge.org)  
> [http://www.contract4j.org](http://www.contract4j.org)
