On 11-May-06, at 7:32 PM, Adam Bloom wrote:

> Hello all,
>
> I feel like I definitely should know this, but how do you test the  
> type
> of an object? For example:
>
> item = ["hello"]
> item.array?
>> true
> item = "hello"
> item.array?
>> false
>
> extending that, how do I test the type of a class that I made?

If you are really interested then:

ratdog:~ mike$ irb
irb(main):001:0> item = ['hello']
=> ["hello"]
irb(main):002:0> item.kind_of?(Array)
=> true
irb(main):003:0> item = 'hello'
=> "hello"
irb(main):004:0> item.kind_of?(Array)
=> false
irb(main):005:0>

may be interesting to you, and you can look at the class of an object  
using the class method:

irb(main):006:0> item.class
=> String

There are plenty of ways to use Ruby without testing an object's  
class, and some good reasons why you might rue caring too much about  
specific classes - look for duck typing in the group's archives.

There are also good reasons to sniff around if you are interested in  
whether things are behaving as expected though.

Hope this helps,

Mike

-- 

Mike Stok <mike / stok.ca>
http://www.stok.ca/~mike/

The "`Stok' disclaimers" apply.