Ruby – test for array

rubysyntax

What is the right way to:

is_array("something") # => false         (or 1)

is_array(["something", "else"]) # => true  (or > 1)

or to get the count of items in it?

Best Answer

You probably want to use kind_of().

>> s = "something"
=> "something"
>> s.kind_of?(Array)
=> false
>> s = ["something", "else"]
=> ["something", "else"]
>> s.kind_of?(Array)
=> true