determine our object's class and its unique objectID and test its relationship to other classes. : kind_of « Reflection « Ruby






determine our object's class and its unique objectID and test its relationship to other classes.


num =1 
num.id # 3 
num.class # Fixnum 
num.kind_of? Fixnum # true 
num.kind_of? Numeric # true 
num.instance_of? Fixnum # true 
num.instance_of? Numeric # false 

 








Related examples in the same category

1.use Object's is_a? or kind_of? methods (they are synonyms)
2.Return value based on parameter type