小编典典

Ruby - 测试数组

all

什么是正确的方法:

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

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

还是要计算其中的项目数?


阅读 79

收藏
2022-04-25

共1个答案

小编典典

您可能想使用kind_of().

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