Unlike instance_of?, is_of? or kind_of? also work if the argument is a superclass or module. : instance_of « Reflection « Ruby






Unlike instance_of?, is_of? or kind_of? also work if the argument is a superclass or module.


myString = "asdf"

puts myString.is_a? Object # => true
puts myString.kind_of? Kernel # => true
puts myString.instance_of? Object # => false

 








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.Is it a string class instance
4.Is it a number
5.Use === to check the class type