# What exactly does obj.is\_a? do?

**URL:** <https://www.ruby-forum.com/t/what-exactly-does-obj-is-a-do/79911>\
**Category:** Ruby\
**Created:** [December 20, 2006, 5:31pm UTC](https://www.ruby-forum.com/t/what-exactly-does-obj-is-a-do/79911 "2006-12-20T17:31:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonlog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/db5fbb/32.png) [@jonlog](https://www.ruby-forum.com/u/jonlog)\
**Post date:** [December 20, 2006, 5:31pm UTC](https://www.ruby-forum.com/t/what-exactly-does-obj-is-a-do/79911/1 "2006-12-20T17:31:24Z")

</div>

I’ve got a theory that I hope someone familiar with the deep recesses of  
Ruby’s internals can confirm or deny.

According to the API, obj.is\_a? “Returns true if /class/ is the  
class of /obj/, or if /class/ is one of the superclasses of /obj/ or  
modules included in /obj/.”  
For the purpose of this question, the only part I’m concerned with is  
“Returns true if /class/ is the class of /obj/”, so let’s ignore the  
rest.//

My theory is that Ruby is simply returning the result of…

@my\_obj.class.object\_id == Klass.object\_id

when I do…

@my\_obj.is\_a?(Klass)

(Don’t forget we’re ignoring the superclass and module stuff it does).

Can anyone confirm or deny this?

I’d also appreciate a hint pointing me to where I could have dredged up  
the answer to this one on my own. Thanks, and happy holidays!

---

<div class="post-metadata">

**Author:** ![jonlog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/db5fbb/32.png) [@jonlog](https://www.ruby-forum.com/u/jonlog)\
**Post date:** [December 20, 2006, 7:22pm UTC](https://www.ruby-forum.com/t/what-exactly-does-obj-is-a-do/79911/2 "2006-12-20T19:22:45Z")

</div>

Jon G. wrote:

> @my\_obj.class.object\_id == Klass.object\_id
> 
> when I do…
> 
> @my\_obj.is\_a?(Klass)

No: is\_a? also returns true when the @my\_obj is an instance of a  
subclass of Klass.

> (Don’t forget we’re ignoring the superclass and module stuff it does).
> 
> Can anyone confirm or deny this?
> 
> I’d also appreciate a hint pointing me to where I could have dredged up  
> the answer to this one on my own. Thanks, and happy holidays!

If you do

ri is\_a?

on command-line, you’ll get immediate answer.

```
Vince
```

---

<div class="post-metadata">

**Author:** ![jonlog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/db5fbb/32.png) [@jonlog](https://www.ruby-forum.com/u/jonlog)\
**Post date:** [December 20, 2006, 7:53pm UTC](https://www.ruby-forum.com/t/what-exactly-does-obj-is-a-do/79911/3 "2006-12-20T19:53:19Z")

</div>

Vincent F. wrote:

> No: is\_a? also returns true when the @my\_obj is an instance of a  
> subclass of Klass.

I realize that, but that’s beyond the scope of the issue I’m having.  
That’s why my original post explicitly said to ignore the superclass and  
module stuff it does (twice).

> If you do
> 
> ri is\_a?
> 
> on command-line, you’ll get immediate answer.

Nope, all I get is the exact same API stuff I’ve already looked at  
before asking, and quoted in my original post.

To clarify, I’m interested in _how_, not _if_, is\_a? determines whether  
@my\_obj.is\_a?(Klass) with no concern for superclasses or modules. I’m  
fairly confident it’s going to take somebody familiar with Ruby’s source  
code, not just the API, to answer this one.
