In Ruby, is it possible to identify whether an object o has a class C as its ancestor in the class hierarchy using any method?
I've given an example below where I use a hypothetical method has_super_class?
to accomplish it. How should I do this in reality?
o = Array.new
o[0] = 0.5
o[1] = 1
o[2] = "This is good"
o[3] = Hash.new
o.each do |value|
if (value.has_super_class? Numeric)
puts "Number"
elsif (value.has_super_class? String)
puts "String"
else
puts "Useless"
end
end
Expected Output:
Number
Number
String
Useless