Forum: Ruby How does one determine an objects class?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
John M. (Guest)
on 2006-02-01 18:15
(Received via mailing list)
Say I've got
str = IO.read("testfile_for_using_file_open")
how can Idetermone what class this object belongs to?
James G. (Guest)
on 2006-02-01 18:21
(Received via mailing list)
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
Austin Z. (Guest)
on 2006-02-01 18:21
(Received via mailing list)
On 01/02/06, John M. <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
Chris G. (Guest)
on 2006-02-01 18:21
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
John M. (Guest)
on 2006-02-01 18:33
(Received via mailing list)
Thanks chaps! I must say that I am impressed with the speedy reply:)

On
Robert K. (Guest)
on 2006-02-02 01:44
(Received via mailing list)
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






















;-)
Antonio C. (Guest)
on 2006-02-02 01:44
(Received via mailing list)
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
This topic is locked and can not be replied to.