# Kind of object

**URL:** <https://www.ruby-forum.com/t/kind-of-object/191300>\
**Category:** Rails\
**Created:** [July 9, 2010, 9:52am UTC](https://www.ruby-forum.com/t/kind-of-object/191300 "2010-07-09T09:52:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [July 9, 2010, 9:52am UTC](https://www.ruby-forum.com/t/kind-of-object/191300/1 "2010-07-09T09:52:33Z")

</div>

Hello All,

I want to know that is there anything in ruby by which i can know that  
which kind of object is this…? Something like is\_object? 🙂

I mean… lets suppose i have two objects of Model ABC and Model DEF…  
then i want to execute some conditions based upon the type of objects.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [July 9, 2010, 9:54am UTC](https://www.ruby-forum.com/t/kind-of-object/191300/2 "2010-07-09T09:54:37Z")

</div>

I think instance\_of can serve my purpose.

Hemant B. wrote:

> Hello All,
> 
> I want to know that is there anything in ruby by which i can know that  
> which kind of object is this…? Something like is\_object? 🙂
> 
> I mean… lets suppose i have two objects of Model ABC and Model DEF…  
> then i want to execute some conditions based upon the type of objects.
> 
> Thanks in advance.

---

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [July 9, 2010, 9:57am UTC](https://www.ruby-forum.com/t/kind-of-object/191300/3 "2010-07-09T09:57:24Z")

</div>

use object.class

---

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [July 9, 2010, 4:46pm UTC](https://www.ruby-forum.com/t/kind-of-object/191300/4 "2010-07-09T16:46:07Z")

</div>

On Fri, Jul 9, 2010 at 03:56, bala kishore pulicherla  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> use object.class

Just beware, if you do a direct comparison, you won’t catch subclasses.

-Dave

–  
Dave A. - Have Pun, Will Babble | Work: [davearonson.com](http://davearonson.com) | /\ ASCII  
-------------------------------------+ Play: [davearonson.net](http://davearonson.net) | / Ribbon  
“Specialization is for insects.” | Life: [dare2xl.com](http://dare2xl.com) | /\   
Campaign  
-Robert A. Heinlein | Wife: [nasjleti.net](http://nasjleti.net) |  
Email\<\>Web

---

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [July 9, 2010, 5:01pm UTC](https://www.ruby-forum.com/t/kind-of-object/191300/5 "2010-07-09T17:01:57Z")

</div>

$ irb

> class MyHash \< Hash ; end  
> =\> nil  
> h = MyHash.new  
> =\> {}  
> h.is\_a? Hash  
> =\> true

Cheers,

Andy

–  
Andy J.  
[http://andyjeffries.co.uk/](http://andyjeffries.co.uk/)#rubyonrails #mysql #jquery  
Registered address: 64 Sish Lane, Stevenage, Herts, SG1 3LS  
Company number: 5452840
