Does ruby 1.9.2 have an is_a? function?

前端 未结 6 1093
忘掉有多难
忘掉有多难 2020-12-17 06:59

I googled that there is an is_a? function to check whether an object is an integer or not.

But I tried in rails console, and it doesn\'t work.

I

6条回答
  •  孤街浪徒
    2020-12-17 07:25

    You forgot to include the class you were testing against:

    "1".is_a?(Integer) # false
    1.is_a?(Integer) # true
    

提交回复
热议问题