Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does ruby 1.9.2 have an is_a? function?

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 ran the code like the following:

 "1".is_a?
 1.is_a?

Did I miss something?

like image 622
mlzboy Avatar asked May 18 '26 23:05

mlzboy


1 Answers

You forgot to include the class you were testing against:

"1".is_a?(Integer) # false
1.is_a?(Integer) # true
like image 149
Andrew Grimm Avatar answered May 21 '26 17:05

Andrew Grimm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!