Is it a string class instance : instance_of « Reflection « Ruby






Is it a string class instance


o = "String"
o.class == String       # true if is o a String

o.instance_of? String   # true if o is a String

 








Related examples in the same category

1.if an object is an instance of a given class with the instance_of? method from Object
2.Use instance_of? for robustness.
3.Unlike instance_of?, is_of? or kind_of? also work if the argument is a superclass or module.
4.Is it a number
5.Use === to check the class type