From: Christopher Dicely Date: 2008-02-10T07:20:07+09:00 Subject: Re: Identifying On Feb 9, 2008 2:00 PM, Adam Akhtar wrote: > If you have an array which contains a mixture of say intergers and > nested arrays, how can you determine whether an element is an array or > not > > ie in psedo code > > array.each do |x| > if x == Array > do something > end > > whats the corect way to write the if statement? Depending on exactly what you want there are two main ways (with several different ways of expressing the most common): if x.instance_of? Array ... # tests if x is an Array (strictly) if x.kind_of? Array ... # test if x is an instance of Array or one of its descendants if x.is_a? Array ... # same as kind_of? if Array === x ... # same as kind_of?, useful to know exists because it lets you match against classes in case statements