Determining type of an object in ruby

前端 未结 5 1209
情书的邮戳
情书的邮戳 2021-01-29 17:46

I\'ll use python as an example of what I\'m looking for (you can think of it as pseudocode if you don\'t know Python):

>>> a = 1
>>> type(a)
&l         


        
5条回答
  •  囚心锁ツ
    2021-01-29 17:57

    you could also try: instance_of?

    p 1.instance_of? Fixnum    #=> True
    p "1".instance_of? String  #=> True
    p [1,2].instance_of? Array #=> True
    

提交回复
热议问题