Check whether a variable is a string in Ruby

后端 未结 6 802
陌清茗
陌清茗 2021-01-30 01:58

Is there anything more idiomatic than the following?

foo.class == String
6条回答
  •  抹茶落季
    2021-01-30 02:46

    You can do:

    foo.instance_of?(String)
    

    And the more general:

    foo.kind_of?(String)
    

提交回复
热议问题