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.
508861510639b56d61eb30e6a28b01d9?d=identicon&s=25 John Maclean (Guest)
on 2006-02-01 17: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?
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2006-02-01 17:21
(Received via mailing list)
On Feb 1, 2006, at 10:13 AM, John Maclean 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 Gray II
31ab75f7ddda241830659630746cdd3a?d=identicon&s=25 Austin Ziegler (Guest)
on 2006-02-01 17:21
(Received via mailing list)
On 01/02/06, John Maclean <info@jayeola.org> 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
De271a04fe7a67b884ce75404c1dcc61?d=identicon&s=25 Chris Gernon (kabigon)
on 2006-02-01 17:21
John Maclean 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
508861510639b56d61eb30e6a28b01d9?d=identicon&s=25 John Maclean (Guest)
on 2006-02-01 17:33
(Received via mailing list)
Thanks chaps! I must say that I am impressed with the speedy reply:)

On
5befe95e6648daec3dd5728cd36602d0?d=identicon&s=25 Robert Klemme (Guest)
on 2006-02-02 00:44
(Received via mailing list)
John Maclean 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






















;-)
E9aaf375ab80de48d8f51b28a43c3a5f?d=identicon&s=25 Antonio Cangiano (Guest)
on 2006-02-02 00:44
(Received via mailing list)
John Maclean 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.