# How does one determine an objects class?

**URL:** <https://www.ruby-forum.com/t/how-does-one-determine-an-objects-class/99761>\
**Category:** Ruby\
**Created:** [February 1, 2006, 5:15pm UTC](https://www.ruby-forum.com/t/how-does-one-determine-an-objects-class/99761 "2006-02-01T17:15:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [February 1, 2006, 5:15pm UTC](https://www.ruby-forum.com/t/how-does-one-determine-an-objects-class/99761/1 "2006-02-01T17:15:00Z")

</div>

Say I’ve got  
str = IO.read(“testfile\_for\_using\_file\_open”)  
how can Idetermone what class this object belongs to?

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [February 1, 2006, 5:21pm UTC](https://www.ruby-forum.com/t/how-does-one-determine-an-objects-class/99761/2 "2006-02-01T17:21:07Z")

</div>

On Feb 1, 2006, at 10:13 AM, John M. wrote:

> Say I’ve got  
> str = IO.read(“testfile\_for\_using\_file\_open”)  
> how can Idetermone what class this object belongs to?

str.class

Hope that helps.

James Edward G. II

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [February 1, 2006, 5:21pm UTC](https://www.ruby-forum.com/t/how-does-one-determine-an-objects-class/99761/3 "2006-02-01T17:21:07Z")

</div>

On 01/02/06, John M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Say I’ve got  
> str = IO.read(“testfile\_for\_using\_file\_open”)  
> how can Idetermone what class this object belongs to?

Which object?

-austin

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [February 1, 2006, 5:21pm UTC](https://www.ruby-forum.com/t/how-does-one-determine-an-objects-class/99761/4 "2006-02-01T17:21:23Z")

</div>

John M. wrote:

> Say I’ve got  
> str = IO.read(“testfile\_for\_using\_file\_open”)  
> how can Idetermone what class this object belongs to?

puts str.class

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [February 2, 2006, 12:44am UTC](https://www.ruby-forum.com/t/how-does-one-determine-an-objects-class/99761/5 "2006-02-02T00:44:48Z")

</div>

John M. wrote:

> Say I’ve got  
> str = IO.read(“testfile\_for\_using\_file\_open”)  
> how can Idetermone what class this object belongs to?

str is of class String.

```
robert

```

😉

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [February 1, 2006, 5:33pm UTC](https://www.ruby-forum.com/t/how-does-one-determine-an-objects-class/99761/6 "2006-02-01T17:33:19Z")

</div>

Thanks chaps! I must say that I am impressed with the speedy reply:)

On

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [February 2, 2006, 12:44am UTC](https://www.ruby-forum.com/t/how-does-one-determine-an-objects-class/99761/7 "2006-02-02T00:44:48Z")

</div>

John M. wrote:

> Say I’ve got  
> str = IO.read(“testfile\_for\_using\_file\_open”)  
> how can Idetermone what class this object belongs to?

John, you can use the Object#class method.  
In your case:

str.class

Use “ri class” for more info.

Cheers,  
Antonio
